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 the plot commands.<br />

h = 10. ∧ [0 : −1 : −4];<br />

≫ taylerr = abs(1 + h + h. ∧ 2/2) − exp(h));<br />

≫ loglog(h, taylerr, ′ − ′ , h, h. ∧ 3, ′ −− ′ )<br />

≫ xlabel( ′ h ′ )<br />

≫ ylabel( ′ Absolute value ′ , ′ of error ′ )<br />

≫ title( ′ Error in quadratic Taylor series approximation to exp(h) ′ )<br />

≫ box off<br />

In this example, we used title, xlabel, and ylabel. These functions reproduce their input<br />

string above the plot and on the x- and y-axes, respectively. We also used the command<br />

box off, which removes the box from the current plot, leaving just the x- and y-axes.<br />

MATLAB will, of course, complain if nonpositive data is sent to loglog (it displays a<br />

warning and plots only the positive data).<br />

Table 6.2. Some commands for controlling the axes.<br />

axis([xmin xmax ymin ymax])<br />

axis auto<br />

axis equal<br />

axis off<br />

axis square<br />

axis tight<br />

xlim([xmin xmax])<br />

ylim([ymin ymax])<br />

Set specified x- and y-axis limits<br />

Return to default axis limits<br />

Equalize data units on x-, y-, and z-axes<br />

Remove axes<br />

Make axis box square (cubic)<br />

Set axis limits to range of data<br />

Set specified x-axis limits<br />

Set specified y-axis limits<br />

The command close closes the current figure window. The command close all causes all<br />

the figure windows to be closed.<br />

Example 1.7 [2] The following program:<br />

• Plots the function 1/(x − 1) 2 + 3/(x − 2) 2 over the interval [0, 3]:<br />

x = linspace(0, 3, 500);<br />

plot(x, 1./(x − 1). ∧ 2 + 3./(x − 2). ∧ 2)<br />

grid on<br />

We specified grid on, which introduces a light horizontal and vertical hashing that extends<br />

from the axis ticks. Because of the singularities at x = 1, 2 the plot is uninformative.<br />

However, by executing the additional command<br />

ylim([0 50])<br />

which focuses on the interesting part of the first plot.<br />

• Plot the epicycloid<br />

0 ≤ t ≤ 10π<br />

{ x(t) = (a + b) cos(t) − b cos((a/b + l)t))<br />

y(t) = (a + b) sin(t) − b sin((a/b + l)t)<br />

8

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

Saved successfully!

Ooh no, something went wrong!