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.3 Functions <strong>in</strong> <strong>Matlab</strong> 355<br />

for C=-1:0.2:1<br />

f=@(x) x.*exp(-C*x.^2);<br />

y=f(x);<br />

l<strong>in</strong>e(x,y)<br />

end<br />

Annotat<strong>in</strong>g <strong>the</strong> plot produces <strong>the</strong> follow<strong>in</strong>g image.<br />

15. Write <strong>the</strong> function M-file.<br />

function y=f(x,c)<br />

y=x.*exp(-c*x.^2);<br />

Set <strong>the</strong> doma<strong>in</strong>.<br />

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

Write <strong>the</strong> for loop.<br />

for C=-1:0.2:1<br />

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

l<strong>in</strong>e(x,y)<br />

end

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

Saved successfully!

Ooh no, something went wrong!