fzero finds the zero of a continuous function of one variable near a starting value x0. It returns the zero x, or NaN if it fails. Additional outputs include the function value at x, an exit flag, and optimization details. fzero accepts a function handle or inline function as input, along with optional options. Examples show finding zeros of sin, cos, and a polynomial function.
Fill out the missing entries in the following table with your answers.pdf
1. Fill out the missing entries in the following table with your answers.
Solution
Optimization Toolbox
fzero
Zero of a continuous function of one variable
Syntax
x = fzero(fun,x0)
x = fzero(fun,x0,options)
x = fzero(fun,x0,options,P1,P2,...)
[x,fval] = fzero(...)
[x,fval,exitflag] = fzero(...)
[x,fval,exitflag,output] = fzero(...)
Description
x = fzero(fun,x0) tries to find a zero of fun near x0, if x0 is a scalar. The value x returned by
fzero is near a point where fun changes sign, or NaN if the search fails. In this case, the search
terminates when the search interval is expanded until an Inf, NaN, or complex value is found.
If x0 is a vector of length two, fzero assumes x0 is an interval where the sign of fun(x0(1))
differs from the sign of fun(x0(2)). An error occurs if this is not true. Calling fzero with such an
interval guarantees fzero returns a value near a point where fun changes sign.
Note Calling fzero with an interval (x0 with two elements) is often faster than calling it with a
scalar x0.
x = fzero(fun,x0,options) minimizes with the optimization parameters specified in the structure
options.
x = fzero(fun,x0,options,P1,P2,...) provides for additional arguments, P1, P2, etc., which are
passed to the objective function, fun. Use options = [] as a placeholder if no options are set.
[x,fval] = fzero(...) returns the value of the objective function fun at the solution x.
[x,fval,exitflag] = fzero(...) returns a value exitflag that describes the exit condition.
[x,fval,exitflag,output] = fzero(...) returns a structure output that contains information about the
optimization.
Note For the purposes of this command, zeros are considered to be points where the function
actually crosses, not just touches, the x-axis.
Arguments
Input Arguments. Table 4-1, Input Arguments, contains general descriptions of arguments
2. passed in to fzero. This section provides function-specific details for fun and options:
fun
The function whose zero is to be computed. fun is a function that accepts a vector x and returns a
scalar f, the objective function evaluated at x. The function fun can be specified as a function
handle.
x = fzero(@myfun,x0)
where myfun is a MATLAB function such as
function f = myfun(x)
f = ... % Compute function value at x
fun can also be an inline object.
x = fzero(inline('sin(x*x)'),x0);
options
Optimization parameter options. You can set or change the values of these parameters using the
optimset function. fzero uses these options structure fields:
Display
Level of display. 'off' displays no output; 'iter' displays output at each iteration; 'final'
displays just the final output; 'notify' (default) dislays output only if the function does not
converge.
TolX
Termination tolerance on x.
Output Arguments. Table 4-2, Output Arguments, contains general descriptions of arguments
returned by fzero. This section provides function-specific details for exitflag and output:
exitflag
Describes the exit condition:
> 0
Indicates that fzero found a zero x.
< 0
No interval was found with a sign change, or a NaN or Inf function value was encountered
during the search for an interval containing a sign change, or a complex function value was
encountered during the search for an interval containing a sign change.
output
Structure containing information about the optimization. The fields of the structure are:
iterations
Number of iterations taken (for fzero, this is the same as the number of function evaluations).
funcCount
Number of function evaluations.
3. algorithm
Algorithm used.
Examples
Calculate by finding the zero of the sine function near 3.
x = fzero(@sin,3)
x =
3.1416
To find the zero of cosine between 1 and 2,
x = fzero(@cos,[1 2])
x =
1.5708
Note that cos(1) and cos(2) differ in sign.
To find a zero of the function
write an M-file called f.m.
function y = f(x)
y = x.^3-2*x-5;
To find the zero near 2
z = fzero(@f,2)
z =
2.0946
Since this function is a polynomial, the statement roots([1 0 -2 -5]) finds the same real zero, and
a complex conjugate pair of zeros.
2.0946
-1.0473 + 1.1359i
-1.0473 - 1.1359i
Optimization Toolbox
fzero
Zero of a continuous function of one variable
Syntax
x = fzero(fun,x0)
x = fzero(fun,x0,options)
x = fzero(fun,x0,options,P1,P2,...)
[x,fval] = fzero(...)
[x,fval,exitflag] = fzero(...)
4. [x,fval,exitflag,output] = fzero(...)
Description
x = fzero(fun,x0) tries to find a zero of fun near x0, if x0 is a scalar. The value x returned by
fzero is near a point where fun changes sign, or NaN if the search fails. In this case, the search
terminates when the search interval is expanded until an Inf, NaN, or complex value is found.
If x0 is a vector of length two, fzero assumes x0 is an interval where the sign of fun(x0(1))
differs from the sign of fun(x0(2)). An error occurs if this is not true. Calling fzero with such an
interval guarantees fzero returns a value near a point where fun changes sign.
Note Calling fzero with an interval (x0 with two elements) is often faster than calling it with a
scalar x0.
x = fzero(fun,x0,options) minimizes with the optimization parameters specified in the structure
options.
x = fzero(fun,x0,options,P1,P2,...) provides for additional arguments, P1, P2, etc., which are
passed to the objective function, fun. Use options = [] as a placeholder if no options are set.
[x,fval] = fzero(...) returns the value of the objective function fun at the solution x.
[x,fval,exitflag] = fzero(...) returns a value exitflag that describes the exit condition.
[x,fval,exitflag,output] = fzero(...) returns a structure output that contains information about the
optimization.
Note For the purposes of this command, zeros are considered to be points where the function
actually crosses, not just touches, the x-axis.
Arguments
Input Arguments. Table 4-1, Input Arguments, contains general descriptions of arguments
passed in to fzero. This section provides function-specific details for fun and options:
fun
The function whose zero is to be computed. fun is a function that accepts a vector x and returns a
scalar f, the objective function evaluated at x. The function fun can be specified as a function
handle.
x = fzero(@myfun,x0)
where myfun is a MATLAB function such as
function f = myfun(x)
f = ... % Compute function value at x
fun can also be an inline object.
x = fzero(inline('sin(x*x)'),x0);
options
Optimization parameter options. You can set or change the values of these parameters using the
optimset function. fzero uses these options structure fields:
5. Display
Level of display. 'off' displays no output; 'iter' displays output at each iteration; 'final'
displays just the final output; 'notify' (default) dislays output only if the function does not
converge.
TolX
Termination tolerance on x.
Output Arguments. Table 4-2, Output Arguments, contains general descriptions of arguments
returned by fzero. This section provides function-specific details for exitflag and output:
exitflag
Describes the exit condition:
> 0
Indicates that fzero found a zero x.
< 0
No interval was found with a sign change, or a NaN or Inf function value was encountered
during the search for an interval containing a sign change, or a complex function value was
encountered during the search for an interval containing a sign change.
output
Structure containing information about the optimization. The fields of the structure are:
iterations
Number of iterations taken (for fzero, this is the same as the number of function evaluations).
funcCount
Number of function evaluations.
algorithm
Algorithm used.
Examples
Calculate by finding the zero of the sine function near 3.
x = fzero(@sin,3)
x =
3.1416
To find the zero of cosine between 1 and 2,
x = fzero(@cos,[1 2])
x =
1.5708
Note that cos(1) and cos(2) differ in sign.
To find a zero of the function
6. write an M-file called f.m.
function y = f(x)
y = x.^3-2*x-5;
To find the zero near 2
z = fzero(@f,2)
z =
2.0946
Since this function is a polynomial, the statement roots([1 0 -2 -5]) finds the same real zero, and
a complex conjugate pair of zeros.
2.0946
-1.0473 + 1.1359i
-1.0473 - 1.1359i
Optimization Toolbox
fzero
Zero of a continuous function of one variable
Syntax
x = fzero(fun,x0)
x = fzero(fun,x0,options)
x = fzero(fun,x0,options,P1,P2,...)
[x,fval] = fzero(...)
[x,fval,exitflag] = fzero(...)
[x,fval,exitflag,output] = fzero(...)
Description
x = fzero(fun,x0) tries to find a zero of fun near x0, if x0 is a scalar. The value x returned by
fzero is near a point where fun changes sign, or NaN if the search fails. In this case, the search
terminates when the search interval is expanded until an Inf, NaN, or complex value is found.
If x0 is a vector of length two, fzero assumes x0 is an interval where the sign of fun(x0(1))
differs from the sign of fun(x0(2)). An error occurs if this is not true. Calling fzero with such an
interval guarantees fzero returns a value near a point where fun changes sign.
Note Calling fzero with an interval (x0 with two elements) is often faster than calling it with a
scalar x0.
x = fzero(fun,x0,options) minimizes with the optimization parameters specified in the structure
options.
x = fzero(fun,x0,options,P1,P2,...) provides for additional arguments, P1, P2, etc., which are
passed to the objective function, fun. Use options = [] as a placeholder if no options are set.
7. [x,fval] = fzero(...) returns the value of the objective function fun at the solution x.
[x,fval,exitflag] = fzero(...) returns a value exitflag that describes the exit condition.
[x,fval,exitflag,output] = fzero(...) returns a structure output that contains information about the
optimization.
Note For the purposes of this command, zeros are considered to be points where the function
actually crosses, not just touches, the x-axis.
Arguments
Input Arguments. Table 4-1, Input Arguments, contains general descriptions of arguments
passed in to fzero. This section provides function-specific details for fun and options:
fun
The function whose zero is to be computed. fun is a function that accepts a vector x and returns a
scalar f, the objective function evaluated at x. The function fun can be specified as a function
handle.
x = fzero(@myfun,x0)
where myfun is a MATLAB function such as
function f = myfun(x)
f = ... % Compute function value at x
fun can also be an inline object.
x = fzero(inline('sin(x*x)'),x0);
options
Optimization parameter options. You can set or change the values of these parameters using the
optimset function. fzero uses these options structure fields:
Display
Level of display. 'off' displays no output; 'iter' displays output at each iteration; 'final'
displays just the final output; 'notify' (default) dislays output only if the function does not
converge.
TolX
Termination tolerance on x.
Output Arguments. Table 4-2, Output Arguments, contains general descriptions of arguments
returned by fzero. This section provides function-specific details for exitflag and output:
exitflag
Describes the exit condition:
> 0
Indicates that fzero found a zero x.
< 0
No interval was found with a sign change, or a NaN or Inf function value was encountered
8. during the search for an interval containing a sign change, or a complex function value was
encountered during the search for an interval containing a sign change.
output
Structure containing information about the optimization. The fields of the structure are:
iterations
Number of iterations taken (for fzero, this is the same as the number of function evaluations).
funcCount
Number of function evaluations.
algorithm
Algorithm used.
Examples
Calculate by finding the zero of the sine function near 3.
x = fzero(@sin,3)
x =
3.1416
To find the zero of cosine between 1 and 2,
x = fzero(@cos,[1 2])
x =
1.5708
Note that cos(1) and cos(2) differ in sign.
To find a zero of the function
write an M-file called f.m.
function y = f(x)
y = x.^3-2*x-5;
To find the zero near 2
z = fzero(@f,2)
z =
2.0946
Since this function is a polynomial, the statement roots([1 0 -2 -5]) finds the same real zero, and
a complex conjugate pair of zeros.
2.0946
-1.0473 + 1.1359i
-1.0473 - 1.1359i
Optimization Toolbox
9. fzero
Zero of a continuous function of one variable
Syntax
x = fzero(fun,x0)
x = fzero(fun,x0,options)
x = fzero(fun,x0,options,P1,P2,...)
[x,fval] = fzero(...)
[x,fval,exitflag] = fzero(...)
[x,fval,exitflag,output] = fzero(...)
Description
x = fzero(fun,x0) tries to find a zero of fun near x0, if x0 is a scalar. The value x returned by
fzero is near a point where fun changes sign, or NaN if the search fails. In this case, the search
terminates when the search interval is expanded until an Inf, NaN, or complex value is found.
If x0 is a vector of length two, fzero assumes x0 is an interval where the sign of fun(x0(1))
differs from the sign of fun(x0(2)). An error occurs if this is not true. Calling fzero with such an
interval guarantees fzero returns a value near a point where fun changes sign.
Note Calling fzero with an interval (x0 with two elements) is often faster than calling it with a
scalar x0.
x = fzero(fun,x0,options) minimizes with the optimization parameters specified in the structure
options.
x = fzero(fun,x0,options,P1,P2,...) provides for additional arguments, P1, P2, etc., which are
passed to the objective function, fun. Use options = [] as a placeholder if no options are set.
[x,fval] = fzero(...) returns the value of the objective function fun at the solution x.
[x,fval,exitflag] = fzero(...) returns a value exitflag that describes the exit condition.
[x,fval,exitflag,output] = fzero(...) returns a structure output that contains information about the
optimization.
Note For the purposes of this command, zeros are considered to be points where the function
actually crosses, not just touches, the x-axis.
Arguments
Input Arguments. Table 4-1, Input Arguments, contains general descriptions of arguments
passed in to fzero. This section provides function-specific details for fun and options:
fun
The function whose zero is to be computed. fun is a function that accepts a vector x and returns a
scalar f, the objective function evaluated at x. The function fun can be specified as a function
handle.
x = fzero(@myfun,x0)
10. where myfun is a MATLAB function such as
function f = myfun(x)
f = ... % Compute function value at x
fun can also be an inline object.
x = fzero(inline('sin(x*x)'),x0);
options
Optimization parameter options. You can set or change the values of these parameters using the
optimset function. fzero uses these options structure fields:
Display
Level of display. 'off' displays no output; 'iter' displays output at each iteration; 'final'
displays just the final output; 'notify' (default) dislays output only if the function does not
converge.
TolX
Termination tolerance on x.
Output Arguments. Table 4-2, Output Arguments, contains general descriptions of arguments
returned by fzero. This section provides function-specific details for exitflag and output:
exitflag
Describes the exit condition:
> 0
Indicates that fzero found a zero x.
< 0
No interval was found with a sign change, or a NaN or Inf function value was encountered
during the search for an interval containing a sign change, or a complex function value was
encountered during the search for an interval containing a sign change.
output
Structure containing information about the optimization. The fields of the structure are:
iterations
Number of iterations taken (for fzero, this is the same as the number of function evaluations).
funcCount
Number of function evaluations.
algorithm
Algorithm used.
Examples
Calculate by finding the zero of the sine function near 3.
x = fzero(@sin,3)
x =
11. 3.1416
To find the zero of cosine between 1 and 2,
x = fzero(@cos,[1 2])
x =
1.5708
Note that cos(1) and cos(2) differ in sign.
To find a zero of the function
write an M-file called f.m.
function y = f(x)
y = x.^3-2*x-5;
To find the zero near 2
z = fzero(@f,2)
z =
2.0946
Since this function is a polynomial, the statement roots([1 0 -2 -5]) finds the same real zero, and
a complex conjugate pair of zeros.
2.0946
-1.0473 + 1.1359i
-1.0473 - 1.1359i
Optimization Toolbox
fzero
Zero of a continuous function of one variable
Syntax
x = fzero(fun,x0)
x = fzero(fun,x0,options)
x = fzero(fun,x0,options,P1,P2,...)
[x,fval] = fzero(...)
[x,fval,exitflag] = fzero(...)
[x,fval,exitflag,output] = fzero(...)
Description
x = fzero(fun,x0) tries to find a zero of fun near x0, if x0 is a scalar. The value x returned by
fzero is near a point where fun changes sign, or NaN if the search fails. In this case, the search
terminates when the search interval is expanded until an Inf, NaN, or complex value is found.
If x0 is a vector of length two, fzero assumes x0 is an interval where the sign of fun(x0(1))
12. differs from the sign of fun(x0(2)). An error occurs if this is not true. Calling fzero with such an
interval guarantees fzero returns a value near a point where fun changes sign.
Note Calling fzero with an interval (x0 with two elements) is often faster than calling it with a
scalar x0.
x = fzero(fun,x0,options) minimizes with the optimization parameters specified in the structure
options.
x = fzero(fun,x0,options,P1,P2,...) provides for additional arguments, P1, P2, etc., which are
passed to the objective function, fun. Use options = [] as a placeholder if no options are set.
[x,fval] = fzero(...) returns the value of the objective function fun at the solution x.
[x,fval,exitflag] = fzero(...) returns a value exitflag that describes the exit condition.
[x,fval,exitflag,output] = fzero(...) returns a structure output that contains information about the
optimization.
Note For the purposes of this command, zeros are considered to be points where the function
actually crosses, not just touches, the x-axis.
Arguments
Input Arguments. Table 4-1, Input Arguments, contains general descriptions of arguments
passed in to fzero. This section provides function-specific details for fun and options:
fun
The function whose zero is to be computed. fun is a function that accepts a vector x and returns a
scalar f, the objective function evaluated at x. The function fun can be specified as a function
handle.
x = fzero(@myfun,x0)
where myfun is a MATLAB function such as
function f = myfun(x)
f = ... % Compute function value at x
fun can also be an inline object.
x = fzero(inline('sin(x*x)'),x0);
options
Optimization parameter options. You can set or change the values of these parameters using the
optimset function. fzero uses these options structure fields:
Display
Level of display. 'off' displays no output; 'iter' displays output at each iteration; 'final'
displays just the final output; 'notify' (default) dislays output only if the function does not
converge.
TolX
Termination tolerance on x.
13. Output Arguments. Table 4-2, Output Arguments, contains general descriptions of arguments
returned by fzero. This section provides function-specific details for exitflag and output:
exitflag
Describes the exit condition:
> 0
Indicates that fzero found a zero x.
< 0
No interval was found with a sign change, or a NaN or Inf function value was encountered
during the search for an interval containing a sign change, or a complex function value was
encountered during the search for an interval containing a sign change.
output
Structure containing information about the optimization. The fields of the structure are:
iterations
Number of iterations taken (for fzero, this is the same as the number of function evaluations).
funcCount
Number of function evaluations.
algorithm
Algorithm used.
Examples
Calculate by finding the zero of the sine function near 3.
x = fzero(@sin,3)
x =
3.1416
To find the zero of cosine between 1 and 2,
x = fzero(@cos,[1 2])
x =
1.5708
Note that cos(1) and cos(2) differ in sign.
To find a zero of the function
write an M-file called f.m.
function y = f(x)
y = x.^3-2*x-5;
To find the zero near 2
z = fzero(@f,2)
z =
14. 2.0946
Since this function is a polynomial, the statement roots([1 0 -2 -5]) finds the same real zero, and
a complex conjugate pair of zeros.
2.0946
-1.0473 + 1.1359i
-1.0473 - 1.1359i
Optimization Toolbox
fzero
Zero of a continuous function of one variable
Syntax
x = fzero(fun,x0)
x = fzero(fun,x0,options)
x = fzero(fun,x0,options,P1,P2,...)
[x,fval] = fzero(...)
[x,fval,exitflag] = fzero(...)
[x,fval,exitflag,output] = fzero(...)
Description
x = fzero(fun,x0) tries to find a zero of fun near x0, if x0 is a scalar. The value x returned by
fzero is near a point where fun changes sign, or NaN if the search fails. In this case, the search
terminates when the search interval is expanded until an Inf, NaN, or complex value is found.
If x0 is a vector of length two, fzero assumes x0 is an interval where the sign of fun(x0(1))
differs from the sign of fun(x0(2)). An error occurs if this is not true. Calling fzero with such an
interval guarantees fzero returns a value near a point where fun changes sign.
Note Calling fzero with an interval (x0 with two elements) is often faster than calling it with a
scalar x0.
x = fzero(fun,x0,options) minimizes with the optimization parameters specified in the structure
options.
x = fzero(fun,x0,options,P1,P2,...) provides for additional arguments, P1, P2, etc., which are
passed to the objective function, fun. Use options = [] as a placeholder if no options are set.
[x,fval] = fzero(...) returns the value of the objective function fun at the solution x.
[x,fval,exitflag] = fzero(...) returns a value exitflag that describes the exit condition.
[x,fval,exitflag,output] = fzero(...) returns a structure output that contains information about the
optimization.
Note For the purposes of this command, zeros are considered to be points where the function
actually crosses, not just touches, the x-axis.
15. Arguments
Input Arguments. Table 4-1, Input Arguments, contains general descriptions of arguments
passed in to fzero. This section provides function-specific details for fun and options:
fun
The function whose zero is to be computed. fun is a function that accepts a vector x and returns a
scalar f, the objective function evaluated at x. The function fun can be specified as a function
handle.
x = fzero(@myfun,x0)
where myfun is a MATLAB function such as
function f = myfun(x)
f = ... % Compute function value at x
fun can also be an inline object.
x = fzero(inline('sin(x*x)'),x0);
options
Optimization parameter options. You can set or change the values of these parameters using the
optimset function. fzero uses these options structure fields:
Display
Level of display. 'off' displays no output; 'iter' displays output at each iteration; 'final'
displays just the final output; 'notify' (default) dislays output only if the function does not
converge.
TolX
Termination tolerance on x.
Output Arguments. Table 4-2, Output Arguments, contains general descriptions of arguments
returned by fzero. This section provides function-specific details for exitflag and output:
exitflag
Describes the exit condition:
> 0
Indicates that fzero found a zero x.
< 0
No interval was found with a sign change, or a NaN or Inf function value was encountered
during the search for an interval containing a sign change, or a complex function value was
encountered during the search for an interval containing a sign change.
output
Structure containing information about the optimization. The fields of the structure are:
iterations
Number of iterations taken (for fzero, this is the same as the number of function evaluations).
16. funcCount
Number of function evaluations.
algorithm
Algorithm used.
Examples
Calculate by finding the zero of the sine function near 3.
x = fzero(@sin,3)
x =
3.1416
To find the zero of cosine between 1 and 2,
x = fzero(@cos,[1 2])
x =
1.5708
Note that cos(1) and cos(2) differ in sign.
To find a zero of the function
write an M-file called f.m.
function y = f(x)
y = x.^3-2*x-5;
To find the zero near 2
z = fzero(@f,2)
z =
2.0946
Since this function is a polynomial, the statement roots([1 0 -2 -5]) finds the same real zero, and
a complex conjugate pair of zeros.
2.0946
-1.0473 + 1.1359i
-1.0473 - 1.1359i
Optimization Toolbox
fzero
Zero of a continuous function of one variable
Syntax
x = fzero(fun,x0)
x = fzero(fun,x0,options)
x = fzero(fun,x0,options,P1,P2,...)
17. [x,fval] = fzero(...)
[x,fval,exitflag] = fzero(...)
[x,fval,exitflag,output] = fzero(...)
Description
x = fzero(fun,x0) tries to find a zero of fun near x0, if x0 is a scalar. The value x returned by
fzero is near a point where fun changes sign, or NaN if the search fails. In this case, the search
terminates when the search interval is expanded until an Inf, NaN, or complex value is found.
If x0 is a vector of length two, fzero assumes x0 is an interval where the sign of fun(x0(1))
differs from the sign of fun(x0(2)). An error occurs if this is not true. Calling fzero with such an
interval guarantees fzero returns a value near a point where fun changes sign.
Note Calling fzero with an interval (x0 with two elements) is often faster than calling it with a
scalar x0.
x = fzero(fun,x0,options) minimizes with the optimization parameters specified in the structure
options.
x = fzero(fun,x0,options,P1,P2,...) provides for additional arguments, P1, P2, etc., which are
passed to the objective function, fun. Use options = [] as a placeholder if no options are set.
[x,fval] = fzero(...) returns the value of the objective function fun at the solution x.
[x,fval,exitflag] = fzero(...) returns a value exitflag that describes the exit condition.
[x,fval,exitflag,output] = fzero(...) returns a structure output that contains information about the
optimization.
Note For the purposes of this command, zeros are considered to be points where the function
actually crosses, not just touches, the x-axis.
Arguments
Input Arguments. Table 4-1, Input Arguments, contains general descriptions of arguments
passed in to fzero. This section provides function-specific details for fun and options:
fun
The function whose zero is to be computed. fun is a function that accepts a vector x and returns a
scalar f, the objective function evaluated at x. The function fun can be specified as a function
handle.
x = fzero(@myfun,x0)
where myfun is a MATLAB function such as
function f = myfun(x)
f = ... % Compute function value at x
fun can also be an inline object.
x = fzero(inline('sin(x*x)'),x0);
options
18. Optimization parameter options. You can set or change the values of these parameters using the
optimset function. fzero uses these options structure fields:
Display
Level of display. 'off' displays no output; 'iter' displays output at each iteration; 'final'
displays just the final output; 'notify' (default) dislays output only if the function does not
converge.
TolX
Termination tolerance on x.
Output Arguments. Table 4-2, Output Arguments, contains general descriptions of arguments
returned by fzero. This section provides function-specific details for exitflag and output:
exitflag
Describes the exit condition:
> 0
Indicates that fzero found a zero x.
< 0
No interval was found with a sign change, or a NaN or Inf function value was encountered
during the search for an interval containing a sign change, or a complex function value was
encountered during the search for an interval containing a sign change.
output
Structure containing information about the optimization. The fields of the structure are:
iterations
Number of iterations taken (for fzero, this is the same as the number of function evaluations).
funcCount
Number of function evaluations.
algorithm
Algorithm used.
Examples
Calculate by finding the zero of the sine function near 3.
x = fzero(@sin,3)
x =
3.1416
To find the zero of cosine between 1 and 2,
x = fzero(@cos,[1 2])
x =
1.5708
Note that cos(1) and cos(2) differ in sign.
19. To find a zero of the function
write an M-file called f.m.
function y = f(x)
y = x.^3-2*x-5;
To find the zero near 2
z = fzero(@f,2)
z =
2.0946
Since this function is a polynomial, the statement roots([1 0 -2 -5]) finds the same real zero, and
a complex conjugate pair of zeros.
2.0946
-1.0473 + 1.1359i
-1.0473 - 1.1359i
Optimization Toolbox