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
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
292 <strong>Chapter</strong> 4 <strong>Programm<strong>in</strong>g</strong> <strong>in</strong> <strong>Matlab</strong><br />
Elim<strong>in</strong>ate complex numbers.<br />
k=real(y)~=y;<br />
y(k)=NaN;<br />
Open a new figure w<strong>in</strong>dow and<br />
replot. Turn on <strong>the</strong> grid.<br />
figure<br />
plot(x,y)<br />
axis([-10,10,-10,10])<br />
grid on<br />
27. Def<strong>in</strong>e <strong>the</strong> anonymous function.<br />
f=@(x) 2+sqrt(x+5);<br />
The doma<strong>in</strong> <strong>of</strong> y = 2 + √ x + 5<br />
is <strong>the</strong> set <strong>of</strong> all real numbers greater<br />
than or equal to −5. Evaluate <strong>the</strong><br />
function on [−5, 10] 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 />
axis([-10,10,-10,10])<br />
grid on