Page 48 - A Guide to MATLAB for Beginners and Experienced Users
P. 48

Graphics         29


                                2
                       To plot x + x + 1 on the interval from −2 to 2 we first make a list X of
                     x values, and then type plot(X, X.ˆ2+X+1). We need to use enough
                     x values to ensure that the resulting graph drawn by “connecting the dots”
                     looks smooth. We’ll use an increment of 0.1. Thus a recipe for graphing the
                     parabola is

                       >> X = -2:0.1:2;
                       >> plot(X, X.ˆ2+X+1)

                     The result appears in Figure 2-6. Note that we used a semicolon to suppress
                     printing of the 41-element vector X. Note also that the command

                       >> plot(X, f1(X))

                     would produce the same results (f1 is defined earlier in the section User-
                     Defined Functions).



                         7



                         6


                         5



                         4


                         3



                         2


                         1



                         0
                         -2      -1.5    -1      -0.5     0       0.5     1       1.5     2
                         Figure 2-6
   43   44   45   46   47   48   49   50   51   52   53