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

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

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

f=@(x) sqrt(9-x.^2);<br />

f=@(x,y) sqrt(1+x);<br />

The doma<strong>in</strong> <strong>of</strong> y = √ 9 − x 2 is<br />

<strong>the</strong> set <strong>of</strong> all real numbers greater than<br />

or equal to −3 and less than or equal<br />

to 3. Evaluate <strong>the</strong> function on [−3, 3]<br />

and plot <strong>the</strong> result.<br />

x=l<strong>in</strong>space(-5,10,200);<br />

y=f(x);<br />

plot(x,y)<br />

Adjust <strong>the</strong> w<strong>in</strong>dow boundaries<br />

and add a grid.<br />

Set up <strong>the</strong> grid.<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 and plot <strong>the</strong> result<strong>in</strong>g<br />

surface.<br />

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

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

axis([-10,10,-10,10])<br />

grid on

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

Saved successfully!

Ooh no, something went wrong!