23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

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.

5 Types of Functions<br />

shape. The makeParabola function shown here constructs and returns a<br />

function handle fhandle for the nested parabola function. This handle gets<br />

passed to fplot:<br />

function fhandle = makeParabola(a, b, c)<br />

% MAKEPARABOLA returns a function handle with parabola<br />

% coefficients.<br />

fhandle = @parabola;<br />

% @ is the function handle constructor<br />

function y = parabola(x)<br />

y = a*x.^2 + b*x + c;<br />

end<br />

end<br />

Assign the function handle returnedfromthecalltoavariable(h) and<br />

evaluate the function at points 0 and 25:<br />

h = makeParabola(1.3, .2, 30)<br />

h =<br />

@makeParabola/parabola<br />

h(0)<br />

ans =<br />

30<br />

h(25)<br />

ans =<br />

847.5000<br />

5-28

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

Saved successfully!

Ooh no, something went wrong!