23.10.2014 Views

Matlab Chapter6.pdf

Matlab Chapter6.pdf

Matlab Chapter6.pdf

SHOW MORE
SHOW LESS

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

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

To open the second figure window and make it the current figure, type<br />

≫ figure(2)<br />

To open a new figure window and make it the current figure, type<br />

≫ figure<br />

Clearing the Figure for a New Plot When a figure already exists, most plotting commands<br />

clear the axes and use this figure to create the new plot. However, these commands do not<br />

reset figure properties, such as the background color or the colormap. If you have set any figure<br />

properties in the previous plot, you might want to use the clf command with the reset option,<br />

≫ clf reset<br />

before creating your new plot to restore the figures properties to their defaults.<br />

clf clears the current figure window. It also resets all properties associated with the axes,<br />

such as the hold state and the axis state.<br />

cla deletes all plots and text from the current axes, i.e. leaves only the x- and y-axes and<br />

their associated information.<br />

For More Information See “Figure Properties” and “Graphics Windows” the Figure in [1].<br />

1.9 Plotting rapidly changing mathematical functions: fplot<br />

In all the graphing examples so far, the x coordinates of the points plotted have been incremented<br />

uniformly, e.g. x = 0 : 0.01 : 4. If the function being plotted changes very rapidly in<br />

some places, this can be inefficient, and can even give a misleading graph.<br />

For example, the statements<br />

≫ x = 0.01 : .001 : .1;<br />

≫ plot(x, sin(1./x))<br />

But if the x increments are reduced to 0.0001, we get another graph instead. For x < 0.04, the<br />

two graphs look quite different.<br />

MATLAB has a function called fplot which uses a more elegant approach. Whereas the<br />

above method evaluates sin(1/x) at equally spaced intervals, fplot evaluates it more frequently<br />

over regions where it changes more rapidly. Here’s how to use it:<br />

≫ fplot( sin(1/x), [0.01 0.1])% no, 1./x not needed!<br />

The general pattern is fplot(fun, lims, tol, N, ′ LineSpec ′ , pl, p2, . . .). The argument list<br />

works as follows.<br />

• fun specifies the function to be plotted.<br />

• The x and/or y limits are given by lims.<br />

• tol is a relative error tolerance, the default value of 2 × 10 −3 corresponding to 0.2%<br />

accuracy.<br />

• At least N + 1 points will be used to produce the plot.<br />

• LineSpec determines the line type.<br />

• p1, p2, . . . are parameters that are passed to fun, which must have input arguments x,<br />

p1, p2, . . . .<br />

The arguments tol, N, and ’LineSpec’ can be specified in any order, and an empty matrix<br />

([ ]) can be passed to obtain the default for any of these arguments.<br />

6

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

Saved successfully!

Ooh no, something went wrong!