Title: Fzero use
1Lecture 6 Fzero use
2Matlab function fzero
X FZERO(FUN,X0), X0 a scalar Attempts to find
a zero of the function FUN near X0. FUN is a
function handle. The value X returned by FZERO
is near a point where FUN changes sign (if FUN
is continuous), or NaN, if the srootfinding search
fails. X FZERO(FUN,X0), X0 a 2-vector.
Assumes that FUN(X0(1)) and FUN(X0(2)) differ in
sign, insuring a root. X FZERO(FUN,X0,OPTIONS).
Solves the equation with default optimization
parameters replaced by values in the string
OPTIONS, an argument created with the OPTIMSET
function.
3Example of fzero use
gtgt options optimset('disp', 'iter', 'tolx',
1.e-15) gtgt fzero(_at_ftest2,0.1 2,options)
Func-count x f(x)
Procedure 2 0.1 -1.6786
initial 3 0.157698 -1.4715
interpolation 4 0.556708
0.601452 interpolation 5
0.440938 -0.143633 interpolation 6
0.463256 -0.0110609
interpolation 7 0.465084 2.0255e-005
interpolation 8 0.465081
-3.08857e-008 interpolation 9
0.465081 -8.61533e-014 interpolation 10
0.465081 0
interpolation Zero found in the interval 0.1,
2 ans 0.4651 gtgt
4Inclass4
Modify ftest2.m to find root of e(-x)-x0 by
Brents method starting at x0.2 and x1.5
5Answer to inclass4
gtgt fzero(_at_ftest2b,0.2 1.5,options)
Func-count x f(x)
Procedure 2 0.2 0.618731
initial 3 0.624325 -0.0887015
interpolation 4 0.571121
-0.0062285 interpolation 5
0.567143 1.13316e-006 interpolation 6
0.567143 -8.15018e-010
interpolation 7 0.567143 -1.11022e-016
interpolation 8 0.567143
-1.11022e-016 interpolation Zero found
in the interval 0.2, 1.5 ans 0.5671
6Practical use of root finding 1)Estimate
approximate position of roots. Use e.g. plot of
function. 2)Find each root separately using
initial points from plot.