Mathematics Previous page   Next Page

Providing Parameter Values Using Nested Functions

One way to provide parameters to the polynomial is to write a single M-file that

The following example illustrates how to find a zero of the cubic polynomial x3 + bx + c, for different values of the coefficients b and c, using this method. To do so, write an M-file with the following code.

The main function, findzero, does two things:

You can call findzero with any values of the coefficients b and c, which are seen by poly because it is a nested function.

As an example, to find a zero of the polynomial with b = 2 and c = 3.5, using the starting point x0 = 0, call findzero as follows.

This returns the zero


Previous page  Parameterizing Functions Called by Function Functions Providing Parameter Values to Anonymous Functions Next page

© 1994-2005 The MathWorks, Inc.