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 297<br />

Draw <strong>the</strong> surface, adjust <strong>the</strong> orientation,<br />

and turn <strong>the</strong> box on for depth.<br />

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

view(130,30)<br />

box on<br />

39. Def<strong>in</strong>e <strong>the</strong> anonymous function.<br />

f=@(x,y) 11-2*x+2*y;<br />

Set up <strong>the</strong> grid.<br />

Open a new figure w<strong>in</strong>dow, replot,<br />

and adjust <strong>the</strong> view so that <strong>the</strong><br />

eye stares down <strong>the</strong> z-axis directly at<br />

<strong>the</strong> xy-plane.<br />

figure<br />

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

view(0,90)<br />

x=l<strong>in</strong>space(-3,3,40);<br />

y=x;<br />

[x,y]=meshgrid(x,y);<br />

Evaluate <strong>the</strong> function at each (x, y)<br />

pair <strong>in</strong> <strong>the</strong> grid.<br />

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

Determ<strong>in</strong>e where x > −1 and<br />

set all entries <strong>in</strong> z equal to NaN where<br />

this contra<strong>in</strong>t is not satisfied.<br />

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

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

z(~k)=NaN;

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

Saved successfully!

Ooh no, something went wrong!