Page 62 - Applied Numerical Methods Using MATLAB
P. 62

PROBLEMS   51
                     >>x1 = [0:0.01:pi/2-0.01]; x2 = [pi/2+0.01:0.01:3*pi/2-0.01];
                     >>x3 = [3*pi/2+0.01:0.01:2*pi];
                     >>y1 = tan(x1); y2 = tan(x2); y3 = tan(x3);
                     >>subplot(222), plot(x1,y1,x2,y2,x3,y3), axis([0 6.3 -10 10])

                (d) Try adjusting the number of intermediate points within the plotting
                    interval as follows.

                     >>x1 = [0:200]*pi/100; y1 = tan(x1);
                     >>x2 = [0:400]*pi/200; y2 = tan(x2);
                     >>subplot(223), plot(x1,y1), axis([0 6.3 -10 10])
                     >>subplot(224), plot(x2,y2), axis([0 6.3 -10 10])
                    From the difference between the two graphs you got, you might have
                    guessed that it would be helpful to increase the number of intermediate
                    points. Do you still have the same idea even after you adjust the range
                    of the y-axis to [−50, +50] by using the following command?

                     >>axis([0 6.3 -50 50])

                 (e) How about trying the easy plotting command ezplot()? Does it answer
                    your desire?

                     >>ezplot(’tan(x)’,0,2*pi)
             1.6 Plotting the Graph of a Sinc Function
                The sinc function is defined as

                                                 sin x
                                          f(x) =                        (P1.6.1)
                                                  x
                whose value at x = 0is


                                  sin x  (sin x)
                       f(0) = lim     =            =  cos x      = 1    (P1.6.2)
                              x→0 x        x           1   x=0
                                                x=0
                We are going to plot the graph of this function over [−4π, +4π].
                 (a) Casually, you may try as follows.

                     >>x = [-100:100]*pi/25; y = sin(x)./x;
                     >>plot(x,y), axis([-15 15 -0.4 1.2])

                     In spite of the warning message about ‘division-by-zero’, you may
                     somehow get a graph. But, is there anything odd about the graph?
                 (b) How about trying with a different domain vector?

                     >>x = [-4*pi:0.1:+4*pi]; y = sin(x)./x;
                     >>plot(x,y), axis([-15 15 -0.4 1.2])
   57   58   59   60   61   62   63   64   65   66   67