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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Section 4.3 Functions <strong>in</strong> <strong>Matlab</strong> 353<br />

4.3 Answers<br />

1.<br />

>> f=@(x) x^2-3*x-4;<br />

>> f(1)<br />

ans =<br />

-6<br />

3.<br />

>> f=@(t) exp(-0.25*t)*(2*cos(t)-s<strong>in</strong>(t));<br />

>> f(1)<br />

ans =<br />

0.1862<br />

5.<br />

>> h=@(u,v) cos(u)*cos(v);<br />

>> h(1,2)<br />

ans =<br />

-0.2248<br />

7. The function M-file:<br />

function y=f(x)<br />

y=x^2-3*x-4;<br />

Call<strong>in</strong>g <strong>the</strong> function from <strong>the</strong> command l<strong>in</strong>e.

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

Saved successfully!

Ooh no, something went wrong!