15.11.2014 Views

Chapter 4: Programming in Matlab - College of the Redwoods

Chapter 4: Programming in Matlab - College of the Redwoods

Chapter 4: Programming in Matlab - College of the Redwoods

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Section 4.1 Logical Arrays 283<br />

That checks.<br />

Next, create <strong>the</strong> rectangular grid and evaluate z at each po<strong>in</strong>t (x, y) <strong>in</strong> <strong>the</strong><br />

grid.<br />

[x,y]=meshgrid(l<strong>in</strong>space(-1,1,50));<br />

z=f(x,y);<br />

Now, f<strong>in</strong>d those values <strong>of</strong> <strong>the</strong> grid that satisfy y < x and y > −x.<br />

k=(y-x);<br />

We want to elim<strong>in</strong>ate from <strong>the</strong> mesh all po<strong>in</strong>ts that do not satisfy this requirement.<br />

z(~k)=NaN;<br />

We can now draw <strong>the</strong> result<strong>in</strong>g mesh, label <strong>the</strong> axes, and provide an orientation.<br />

mesh(x,y,z)<br />

xlabel(’x-axis’)<br />

ylabel(’y-axis’)<br />

zlabel(’z-axis’)<br />

box on<br />

view(145,20)<br />

The result is shown <strong>in</strong> Figure 4.5(a).<br />

An <strong>in</strong>terest<strong>in</strong>g view is provided by <strong>the</strong> follow<strong>in</strong>g command, <strong>the</strong> result <strong>of</strong> which<br />

is shown <strong>in</strong> Figure 4.5(b). In this view, we’ve decl<strong>in</strong>ed to rotate <strong>the</strong> xy-axes, but<br />

elevated our eye 90 ◦ , so that we are gaz<strong>in</strong>g directly down at <strong>the</strong> xy-plane. This<br />

view clearly shows that we have sketched <strong>the</strong> surface <strong>of</strong> a region <strong>in</strong> <strong>the</strong> rectangular<br />

doma<strong>in</strong> restricted to (x, y) pairs satisfy<strong>in</strong>g y < x and y > −x.<br />

view(0,90)

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

Saved successfully!

Ooh no, something went wrong!