02.03.2016 Views

MATLAB by rudra pratap

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2.3 Lesson 3: Creating and Printing Simple Plots<br />

'27<br />

EXERCISES<br />

1. A simple sine plot: Plot y = sin x, 0 :::; x :::; 21r, taking 100 linearly<br />

spaced points in the given interval. Label the axes and put "Plot created <strong>by</strong><br />

yourname" in the title.<br />

2. Line styles: Make the same plot as in Exercise 1, but rather than displaying<br />

the graph as a curvf!, show the unconnected data points. To display the<br />

Jata points with small circles, uc plot (x, y, 'o'). [Hint: You may look into<br />

Section 6.1 on page 175 if yon wish.] Now combine the two plots with the<br />

command plot (x, y, x, y, 'o') to show the line through the data points as<br />

well as the distinct data points.<br />

3. An exponentially decaying sine plot: Plot y = e-0.4x sin x, 0 :::; x :::; 471",<br />

taking 10, 50, and 100 points in the interval. [Be careful about computing<br />

y. You need array multiplication between exp(-0.4*x) and sin (x) . See<br />

Section 3.2.1 on page 73 for more discussion on array operations.]<br />

4. Space curve: Use the command plot3 (x, y, z) to plot the circular helix<br />

x(t) = sint, y(t) = cos t, z(t) = t, 0 ::=;; t ::=;; 20.<br />

5. On-line help: Type help plot on the <strong>MATLAB</strong> prompt and hit return. If<br />

too much text flashes <strong>by</strong> the screen, type more on, hit return, and then type<br />

help plot again. This should give you paged screen output. Read through<br />

the on-line help. To move to the next page of the screen output, simply press<br />

the spacebar.<br />

6. Log-scale plots: The plot commands semilogx, semilogy, and loglog plot<br />

the x-values, the y-values, and both x- and y-values on a log10 scale, respectively.<br />

Create a vector x=O : 10: 1000. Plot x vs. x3 using the three log-scale<br />

plot commands. [Hint: First, compute y=x. 3 and then use semilogx (x, y) ,<br />

etc.]<br />

7. Overlay plots: Plot y = cos x and z = 1- x22 + : for 0 ::=;; x ::=;; 1r on the same<br />

plot. You might like to read Section 6.1.5 on pagf! 179 to learn how to plot<br />

multivle curves on the same graph. [Hint: You can use plot (x, y, x, z, ' -- ' )<br />

or you can plot the first curve, use the hold on command, and then plot the<br />

second curve on top of the first one.]<br />

8. Fancy plots: Go to Section 6.1.6 and look at the examples of specialized 2-D<br />

plots given there. Reproducf! any of the plots you like.<br />

9. A very difficult plob Use yonr knowledge of splines and interpolation to<br />

dmw a lizard (iust kiddin.o;) .

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!