You are on page 1of 21

Numerical Methods

Roots of Nonlinear Equations


Topic: Other Methods
Lecture’s Goals
• Let us introduce other methods for Solving
Equations of one Variable; these include the
following:

• Linear Interpolation
• Muller’s Method
• Fixed Point Iteration
Linear Interpolation or Regula Falsi
• The bisection method is not very efficient. We
would like to converge to the root at a faster
rate with a different algorithm.

• One of these method is linear interpolation


method or the method of false position
(Latinized version Regula Falsi )
Method of Linear Interpolation: Regula Falsi
Do while |x2 - x1| >= tolerance value 1
or |f(x3)|>= tolerance value 2

Set x3 = x2 - f(x2)*(x2 - x1)/(f(x2)-f(x1))

IF f(x3) of opposite sign of f(x1);


Set x2 = x3;
ELSE
Set x1 = x3;
ENDIF
END loop
Linear Interpolation method
The program uses the slope
of the two points to find the
intersection. However, the
upper bound is kept
constant.

The program uses a similar


triangle to estimate the
location of the root.
Example:
• Let us solve the following 50

problem:
x5 + x3 + 4x2 - 3x – 2 = 0 40

Then f(x) = x5 + x3 + 4x2 - 3x


–2 30

df/dx = 5x4 + 3x2 + 8x - 3

f(x)
20
• Let us first draw a graph
and see where are the roots;
10
• The roots are between (-
1.7,-1.3), (-1,0), & (0.5,1.5) 0

• Then let us write a


computer program in -10

MATLAB that will


compute the root. -20
-2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0
x
Computer Program in MATLAB
% This Uses Regula Falsi method to find the roots of F(x)=0.
% Input: xleft,xright = left and right brackets of the root
% n = (optional) number of iterations; default: n =15
% Output: x = estimate of the root
n=15; xleft = -2.0; xright=-1.5;
a = xleft; b =xright; % Copy original bracket to local variables
fa = a^5+ a^3 + 4.*a^2 - 3*a - 2.0; % Initial values
fb = b^5+ b^3 + 4.*b^2 - 3*b - 2.0;
fprintf(' k a xmid b f(xmid)\n');
for k=1:n
xm = b - fb*((b-a)/(fb-fa)); % Minimize roundoff
fm = xm^5+ xm^3 + 4.*xm^2 - 3*xm - 2.0; % f(x) at xm
fprintf('%3d %12.8f %12.8f %12.8f %12.3e\n',k,a,xm,b,fm);
if sign(fm) == sign(fa)
a = xm; fa = fm;
else
b = xm; fb = fm;
end
end
Results
Result of the computer program: xleft = -2.0 , xright = -1.5 and iterations n = 15.
k a xmid b f(xmid)
1 -2.00000000 -1.51293760 -1.50000000 3.047e-001
2 -2.00000000 -1.52024707 -1.51293760 1.715e-001
3 -2.00000000 -1.52432710 -1.52024707 9.556e-002
4 -2.00000000 -1.52658902 -1.52432710 5.292e-002
5 -2.00000000 -1.52783825 -1.52658902 2.921e-002
6 -2.00000000 -1.52852674 -1.52783825 1.609e-002
7 -2.00000000 -1.52890574 -1.52852674 8.856e-003
8 -2.00000000 -1.52911424 -1.52890574 4.871e-003
9 -2.00000000 -1.52922890 -1.52911424 2.679e-003
10 -2.00000000 -1.52929195 -1.52922890 1.473e-003
11 -2.00000000 -1.52932661 -1.52929195 8.097e-004
12 -2.00000000 -1.52934566 -1.52932661 4.451e-004
13 -2.00000000 -1.52935614 -1.52934566 2.447e-004
14 -2.00000000 -1.52936190 -1.52935614 1.345e-004
15 -2.00000000 -1.52936506 -1.52936190 7.394e-005

The root value is x = -1.529365


Muller’s Method

• Muller’s method is an interpolation method that


uses quadratic interpolation rather than linear.

• A second degree polynomial is used to fit three


points in the vicinity of the root.
Muller’s Method
Do while |x2 - x1| >= tolerance value 1
or |f(x3)| >= tolerance value 2

c1 = (f(x2)-f(x1))/(x2 - x1)
c2 = (f(x3)-f(x2))/(x3 - x2)
d1 = (c2-c1)/(x3 - x1)
s = c2 + d1 *(x3 - x2)

x4 = x3 - 2*f(x3)/
[s + sign(s)*sqrt( s^2 -4*f(x3)*d1]
Set x1 = x2;
Set x2 = x3;
Set x3 = x4;
END loop
Muller’s Method

This method uses a


Newton form of an
interpolating polynomials.
Example for Muller method:
• Let us solve the following 50
problem again for Muller
method: 40
x5+ +x3 4x2- 3x – 2 = 0
Then f(x) = x5 + x3 + 4x2 - 3x – 2 30

• Let us first draw a graph and

f(x)
20

see where are the roots;


• The roots are between (-1.7,- 10

1.3), (-1,0), & (0.5,1.5)


0
• Then let us write a computer
program in MATLAB that
-10
will compute the root.
-20
-2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0
x
Computer Program in MATLAB
% Muller method to find the roots of F(x)=0
% Input:xleft,xcenter,xright =left, center and right points near the root
% n = (optional) number of iterations; default: n =6
% Output: xn = estimate of the root
n=10; xleft = -2.0; xright = -1.5; xcenter=(xleft + xright)/2.;
a = xleft; b =xcenter; c =xright;
fa = a^5+ a^3 + 4.*a^2 - 3*a - 2.0; % Initial values
fb = b^5+ b^3 + 4.*b^2 - 3*b - 2.0;
fc = c^5+ c^3 + 4.*c^2 - 3*c - 2.0;
fprintf(' k a b c xmid f(xmid)\n');
for k=1:n
c1 = (fb-fa)/(b-a); c2 = (fc-fb)/(c-b);
d1 = (c2-c1)/(c-a);
s = c2 -(c-b)*d1;
xm = c - 2*fc/(s + sign(s)*sqrt(s^2 - 4*fc*d1));
fb = xm^5+ xm^3 + 4.*xm^2 - 3*xm - 2.0; % new f value
fprintf('%3d %12.8f %12.8f %12.8f %12.8f %12.3e\n',k,a,b,c,xm,fm);
a = b; fa = fb;
b = c; fb = fc;
c = xm; fc = fm;
end
Results
Result of the computer program: xleft = -2.0 , xright = -1.5 and iterations n = 10.

k a b c xmid f(xmid)
1 -2.00000000 -1.75000000 -1.50000000 -1.51271936 7.394e-005
2 -1.75000000 -1.50000000 -1.51271936 -1.51272104 7.394e-005
3 -1.50000000 -1.51271936 -1.51272104 -1.51272189 7.394e-005
4 -1.51271936 -1.51272104 -1.51272189 -1.51272189 7.394e-005
5 -1.51272104 -1.51272189 -1.51272189 -1.51271884 7.394e-005
6 -1.51272189 -1.51272189 -1.51271884 -1.51271884 7.394e-005
7 -1.51272189 -1.51271884 -1.51271884 -1.51271884 7.394e-005
8 -1.51271884 -1.51271884 -1.51271884 -1.51271884 7.394e-005
9 -1.51271884 -1.51271884 -1.51271884 -1.51271884 7.394e-005
10 -1.51271884 -1.51271884 -1.51271884 -1.51271884 7.394e-005

The root value is x = -1.5127


Fixed-Point Iteration Method
• The method uses an iterative scheme to find the root.
• The equation is rewritten to obtain new equation in terms of x.

f(x) = a3 x3 + a2 x2 + a1 x + a0 = 0

g(x) = - [( a3/a1 ) x3 + (a2 /a1) x2 + (a0 /a1) ]


Fixed-Point Iteration Method

• Problem is that the method only converge for a small range.

| g’(x) | < 0.5


Fixed-Point Iteration Method
Rewrite f(x) -> g(x)

IF | g’(x) |< 0.5


Do while |xk+1 - xk| >= tolerance
value
xk+1 = g(xk);
k = k+1;
END loop
ENDIF
Fixed Point Iteration
Example: Suppose we have
Functional Plot
f(x) = 5x3 -10x + 3
15
Then a new function is
10
g(x) = 0.5x3 + 0.3
g’(x) = 1.5x2 5

f(x)
-3 -2 -1 0 1 2
for 0.1<x<0.5 -5

| g’(x)| < 0.5 -10

-15

-20
x value
Computer Program in MATLAB
% It Uses fixed Point Iteration to find the roots
% of x = 5x^3 - 10x + 3
% Input: x0 = initial guess
% left = left boundary
% right = right boundary
% n = (optional) number of iterations; default: n =8
% Output: x = estimate of the root
n=10; x0 = 0.1; left = 0.0; right = 0.5;
x = x0; % Initial Guess
gleft = 1.5*left^2;
gright = 1.5*right^2;
fprintf('left hand boundary is %8.4f and g`(x) = %8.4f\n',left,gleft);
fprintf('right hand boundary is %8.4f and g`(x) = %8.4f\n\n',right,gright);
if( (abs(gleft) > 0.5)|(abs(gright)> 0.5)) break; end

fprintf(' k x g(x) abs(x(k+1)-x(k))\n\n');


for k=1:n
g = 0.5*x^3 + 0.3;
diff = abs(g - x);
fprintf('%3d %12.6f %12.6f %18.5e\n',k-1,x,g,diff);
x = g;

end
Results
Result of the computer program: xleft = -2.0 , xright = -1.5 and iterations n = 10.
left hand boundary is 0.0000 and g`(x) = 0.0000
right hand boundary is 0.5000 and g`(x) = 0.3750

k x g(x) abs(x(k+1)-x(k))

0 0.100000 0.300500 2.00500e-001


1 0.300500 0.313568 1.30676e-002
2 0.313568 0.315416 1.84810e-003
3 0.315416 0.315690 2.74180e-004
4 0.315690 0.315731 4.09517e-005
5 0.315731 0.315737 6.12267e-006
6 0.315737 0.315738 9.15534e-007
7 0.315738 0.315738 1.36904e-007
8 0.315738 0.315738 2.04721e-008
9 0.315738 0.315738 3.06131e-009

The root value is x = 0.31738


Summary

• Regula Flasi (linear interpolation) - need to know the


function and two bounds.
• Muller’s method -need to know the f(x) and 3 values.
• Secant - need to know f(x) and two bounds.
• Newton’s - need to know f(x) and f’(x) and an initial
guess.

You might also like