The Newton-Rapshon is an open method and is one of the most used because of its speed and effectiveness. This is a variant of the fixed point method. The difference is found in the iteration equation that is given by:
According to the geometric definition, the method works as explained below:
1. Start by drawing a tangent line to the graph of f(X) at the point (X0,f(X0)), where X0 is the initial approximation.
2. The previous tangent line intersects the x-axis at a point (X1,0), so with this value we draw a tangent line at the point: (X1,f(X1)) of the curve f (X).
3. Steps 1 and 2 are repeated and consequently the cut points of the tangent lines approach more and more the root of f (X), when the method converges.
PSEUDOCODE OF NEWTON-RAPSHON
write ('Newton-Rapshon method')
read fx, df, x0, tol, niter
fx = convert the input fx of the user to function
df = convert the input df of the user to function
counter = 0
error = tol + 1
while error> tol and fx (x0) ≠ 0 and df (x0) ≠ 0 and counter <niter do
counter = counter + 1
write table with this information (Ite, Xn, f (Xn), df (Xn), error)
x1 = x0-f (x0) / df (x0)
error = | x1-x0 |
x0 = x1
end while
if fx (x0) == 0
write ('This number is root: x0')
else if
write ('This number x1 is an approximation to a root with a tolerance of: tol')
else if
write ('It is a possible multiple root')
else
write ('Failure the number of iterations')
end
CODE OF NEWTON-RAPSHON
clc
clear all
disp ('Newton-Rapshon Method');
fx = input ('Enter the function:', 's');
df = input ('Enter the derivative of the function:', 's');
x0 = input ('Enter the initial approach:');
tol = input ('Enter a tolerance:');
niter = input ('Enter the maximum number of iterations:');
fx = inline (fx);
df = inline (df);
counter = 0;
error = tol + 1;
while error> tol && fx (x0) ~ = 0 && df (x0) ~ = 0 && counter <niter
counter = counter + 1;
fprintf ('Iter:% 2i \ t Xn =% f \ tf (Xn) =% f \ t df (Xn) =% f \ t Error =% f \ n', counter, x0, fx (x0), df (x0), error)
x1 = x0-fx (x0) / df (x0);
error = abs (x1-x0);
x0 = x1;
end
if fx (x0) == 0
disp ('This number is root:')
disp (x0)
elseif error <tol
disp ('This number ... is an approximation to a root with a tolerance of:')
disp (x1)
disp (tol)
elseif df (x0) == 0
disp ('It is a possible multiple root:')
disp (x1)
else
disp ('Failure the number of iterations')
end