]>

The FZERO Function

The fzero function tries to find a root of a function near an initial value that you supply. First, define a function that can be passed as an argument to the fzero function. Then, call fzero to find the roots.

    >> fzero( 'my_function', x0 )

The above command finds the x value that is nearest to the value in x0 that will cause the function computed by my_function to return a value of zero.

The fzero function can also be called with a string of characters that represents the function to be evaluated, instead of defining a new function.

    >> fzero( '-x^2+10' , 3 )

The fzero function can also be called with a range of x values that limits the range to search for a valid root.

    >> fzero( '-x^2+10' , [3 5] )

The fzero function can also be called to find the root of a polynomial using the polyval command. Use the following command to find the root of y= x 3 +2 x 2 +3x+4 MathType@MTEF@5@5@+=feaafiart1ev1aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLnhiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqr1ngBPrgifHhDYfgasaacH8YjY=vipgYlh9vqqj=hEeeu0xXdbba9frFj0=OqFfea0dXdd9vqai=hGuQ8kuc9pgc9q8qqaq=dir=f0=yqaiVgFr0xfr=xfr=xb9adbaqaaeGaciGaaiaabeqaamaabaabaaGcbaGaamyEaiabg2da9iaadIhadaahaaWcbeqaaiaaiodaaaGccqGHRaWkcaaIYaGaamiEamaaCaaaleqabaGaaGOmaaaakiabgUcaRiaaiodacaWG4bGaey4kaSIaaGinaaaa@4356@ :

    >> fzero( 'polyval([1 2 3 4],x)', 0 )

It is also possible to find the root of a function that requires more than one input, if only one of the inputs to the function is a variable. For example, let's say we want to find where a polynomial crosses the x-axis and the coefficients of our polynomial are stored in the vector c. The command to evaluate the polynomial for a value in x is polyval(c,x). We can find the roots of this polynomial with this syntax:

    >> fzero( @(x)polyval(c,x), x0 )

The @(x) piece indicates that we wish to treat x as the variable in the function polyval(c,x). The x0 argument is still the initial guess for the root of this function. Note: Be sure that c has been assigned its desired value before executing this command.