Calculate
by finding the zero of the sine function near
3
.
Find the zero of cosine between 1
and 2
.
Note that
and
differ in sign.
Find a zero of the function f(x) = x3 – 2x – 5.
First, write a file called f.m
.
Save f.m
on your MATLAB® path.
Find the zero of f(x)near 2
.
Since f(x)
is a polynomial, you canfind the same real zero, and a complex conjugate pair of zeros, usingthe
roots
command.
ans =
2.0946
-1.0473 + 1.1359i
-1.0473 - 1.1359i
Find the root of a function that has an extra parameter.
Plot the solution process by setting some plot functions.
Define the function and initial point.
Examine the solution process by setting options that include plot functions.
Run fzero
including options
.
![](http://www.mathworks.com/help/releases/R2015a/examples/matlab/NondefaultOptionsExample_01.png)
Solve a problem that is defined by a problem structure.
Define a structure that encodes a root-finding problem.
Solve the problem.
Find the point where exp(-exp(-x)) = x
, and display information about the solution process.
Func-count x f(x) Procedure
2 1 -0.307799 initial
3 0.544459 0.0153522 interpolation
4 0.566101 0.00070708 interpolation
5 0.567143 -1.40255e-08 interpolation
6 0.567143 1.50013e-12 interpolation
7 0.567143 0 interpolation
Zero found in the interval [0, 1]
x =
0.5671
fval =
0
exitflag =
1
output =
intervaliterations: 0
iterations: 5
funcCount: 7
algorithm: 'bisection, interpolation'
message: 'Zero found in the interval [0, 1]'
fval
= 0 means fun(x) = 0
, as desired.