Text-only Table of Contents (frame/ no frame)
(25) Nested Matlab function example Previous Top Next

  Nested Function and Function Handle Example


Find a zero of a cubic polynomial x^3+b*x+c for different values of b and c near x0.

Try:

function y = findzero(b, c, x0)
options = optimset('Display', 'off'); % Turn off Display
y = fzero(@poly, x0, options);
    function y = poly(x) % Compute the polynomial.
        y = x^3 + b*x + c;
    end
end

x = findzero(2, 3.5, 0)

Previous Top Next


Nested_func_example.src  last modified Oct 17, 2007 Introduction Table of Contents
(frame/no frame)
Printable
(single file)
© Dartmouth College