Lab 04: Plotting

Objects

  • Learn how to create and label two-dimensional plots
  • Learn how to adjust the appearance of the plots
  • Learn how to create three-dimensional plots

 

Background

It is difficult to understand the mount of data in a large array. No one can make sense of a thousand numbers displayed on the screen. However, graphing techniques can make the information in the array easier to understand. Plotting an array on the screen is an essential tool for understanding and interpreting the numerical results produced by a MATLAB program, and is also useful for debugging (finding errors in your program). With a graph, it is easy to identify trends, pick out highs and lows, and isolate data points that may be measurement or calculation errors.

Questions

  1. Plot the following functions on the same graph for x values from -π to π, selecting spacing to create a smooth plot:
    $y1 = \sin (x)$
    $y2 = \sin (2x)$
    $y3 = \sin (3x)$
  2. Adjust the plot created in Question 1 so that:
    • Line 1 is red and dashed.
    • Line 2 is blue and solid.
    • Line 3 is green and dotted.
    Do not include markers on any of the graphs. In general, markers are included only on plots of measured data, not for calculated values.
  3. Write the commands for drawing the curve:
    $f(x,y) = - {\left( {\frac{x}{5}} \right)^2} - {\left( {\frac{y}{2}} \right)^2} - 16$
    for -5 ≤ x ≤  5 and -5 ≤ y ≤ 5. Using the surf function. (You may need to review Lab03,Session 3.3)
  4. When interest is compounded continuously, the following equation represents the growth of your savings:
    $P = {P_0} \cdot {e^{r \cdot t}}$ 
    In this equation,
      $P$ current balance
      ${P_0}$  initial balance
      $r$ growth constant, expressed as a decimal fraction
      $t$ time invested.
    Determine the amount in your account at the end of each year if you invest $1000 at 8% (0.08) for 30 years. (Make a table.)
    Create a figure with four subplots. Plot time on the x-axis and current balance P on the y-axis.
    1. In the first quadrant, plot t versus P in a rectangular coordinate system.
    2. In the second quadrant, plot t versus P, scaling the x-axis logarithmically.
    3. In the third quadrant, plot t versus P, scaling the y-axis logarithmically.
    4. In the fourth quadrant, plot t versus P, scaling both axes logarithmically
    Which of the four plotting techniques do you think displays the data best?
  5. Using subplots to create the plots in this question. Let the vector
    G = [68, 83, 61, 70, 75, 82, 57, 5, 76, 85, 62, 71, 96, 78, 76, 68, 72, 75, 83, 93]
    represent the distribution of the final grades in the EE3001 course.
    1. Use MATLAB to sort the data and create a bar of the scores. (Use help sort to get the detail information)
    2. Create a histogram of the scores, using histogram.
    3. Assume the following grading scheme is used
      A > 90 to 100
      B > 80 to 90
      C > 70 to 80
      D > 60 to 70
      E > 0 to 60
      Use the histogram function and an appropriate edges vector to create a histogram showing the grade distribution.
    4. Repeat part c but normalize the data using the 'countdensity' option.