Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
• MATLAB’s fzero provides the best qualities of both bracketing methods and
open methods.
– Using an initial guess:
xc = fzero(function, x0)
[xc, fxc] = fzero(function, x0)
• function is a function handle to the function being evaluated
• x0 is the initial guess
• xc is the computed root
• fxc is the function evaluated at that root
– Using an initial bracket:
xc = fzero(function, [x0 x1])
[xc, fxc] = fzero(function, [x0 x1])
• As above, except x0 and x1 are guesses that must bracket a
sign change
1
fzero Options
• Options may be passed to fzero as a third input argument - the options are
a data structure created by the optimset command
fzero Example
Search for a zero in the interval [1.092, -1.9671]:
xc = 6.823278038280194e-001
Our Newton’s code
Total Function evaluation=35 Total Function evaluation=14
Total no of iteration=23 Total no of iteration=7
4
fzero Example
f=inline('x^3+x-1');
option=optimset('display','iter');
[xc]=fzero(f,[0 1],option);
Func-count x f(x) Procedure
2 1 1 initial
3 0.5 -0.375 bisection
4 0.636364 -0.105935 interpolation
5 0.68491 0.00620153 interpolation
6 0.682225 -0.000246683 interpolation
7 0.682328 -5.43508e-007 interpolation
8 0.682328 1.50102e-013 interpolation
9 0.682328 0 interpolation
Zero found in the interval [0, 1]
xc = 6.823278038280194e-001
Our Bisection code
Total Function evaluation=9 Total Function evaluation=12
Total no of iteration=8 Total no of iteration=10
5
5.000000000000000e-001
b = poly([0.5 -1])
• Finds f(x) where f(x) =0 for x=0.5 and x=-1
• MATLAB reports b = [1.000 0.5000 -0.5000]
• This corresponds to f(x)=x2+0.5x-0.5
f=polyval(a, 1)
• This calculates f(1), which MATLAB reports as f=-0.2500
8