Graphics Programs Reference
In-Depth Information
Inspecting the plot of the function, wesuspect that the smallest positivezero is a
double root near x
2. Bisection and Brent's methodwouldnot workhere, since they
depend on the function changing its sign at the root. The same argument applies to
the function newtonRaphson .But there no reasonwhy the unrefinedversion of the
Newton-Raphsonmethod shouldnot succeed.We used the following program, which
prints the number of iterations in addition to the root:
=
function [root,numIter] = newton
simple(func,dfunc,x,tol)
% Simple version of Newton-Raphson method used in Example 4.7.
_
if nargin < 5; tol = 1.0e6*eps; end
fori=1:30
dx = -feval(func,x)/feval(dfunc,x);
x=x+dx;
if abs(dx) < tol
root = x; numIter = i; return
end
end
root = NaN
The twofunctionscalledbythe program are
functiony=fex4
7(x)
% Function used in Example 4.7.
y=xˆ4-6.4*xˆ3+6.45*xˆ2+20.538*x-31.752;
_
functiony=dfex4
7(x)
% Function used in Example 4.7.
y = 4.0*xˆ3 - 19.2*xˆ2 + 12.9*x + 20.538;
_
Here are the results:
_
_
_
>> [root,numIter] = newton
simple(@fex4
7,@dfex4
7,2.0)
root =
2.1000
numIter =
27
It canbe shown that near amultiple root the convergence of the Newton-Raphson
methodislinear, rather than quadratic, which explains the large number of iterations.
Convergence to amultiple root can bespeededupbyreplacing the Newton-Raphson
Search WWH ::




Custom Search