Lecture3 - Roots of Equations - 04march2024 - NK - v1
Lecture3 - Roots of Equations - 04march2024 - NK - v1
COMPUTATIONAL METHODS IN
ENGINEERING
Part 2 – Roots of Equation
f n ( x ) = ao + a1 x + a2 x + 2
+ an x n
f 2 ( x ) = a ( x − x2 ) + b ( x − x2 ) + c
2
Müller Method
2. The parabola should intersect the three points xo , f ( xo ) , x1 , f ( x1 ) ,
x2 , f ( x2 ) . ▪ The coefficients of the polynomial can be estimated by
▪ substituting three points to give.
f ( xo ) = a ( xo − x2 ) + b ( xo − x2 ) + c
2
f ( x2 ) = a ( x1 − x2 ) + b ( x1 − x2 ) + c
2
f ( x3 ) = a ( x2 − x2 ) + b ( x2 − x2 ) + c
2
3. Three equations can be solved for three unknowns, a, b, c. Since two of the
terms in the 3rd equation are zero, it can be immediately solved for c=f(x2).
f ( xo ) − f ( x2 ) = a ( xo − x2 ) + b ( xo − x2 )
2
f ( x1 ) − f ( x2 ) = a ( x1 − x2 ) + b ( x1 − x2 )
2
Müller Method
Algebraic manipulation can then be used to solve for the remaining coefficients,
a and b.
h0 = x1 − x0 h1 = x2 − x1
f ( x1 ) − f ( x0 ) f ( x2 ) − f ( x1 )
0 = 1 =
x1 − x0 x2 − x1
( 0 1)
+ − ( 0 1 ) a = h0 0 + h11 Solve for a and b
+
2
h h b h h
h1 b − h12
a = h11
1 − 0
a = b = ah1 + 1 c = f ( x2 )
h1 + h0
Müller Method
• Roots can be found by applying an alternative form of quadratic
formula:
−2c
x3 = x2 +
b b 2 − 4ac
x3 − x2
a = 100%
x3
• ± term yields two roots, the sign is chosen to agree with b. This will
result in a largest denominator, and will give root estimate that is closest
to x2.
Müller Method
• Once x3 is determined, the process is repeated using the
following guidelines:
1. If only real roots are being located, choose the two
original points that are nearest the new root estimate, x3.
2. If both real and complex roots are estimated, employ a
sequential approach just like in secant method, x1, x2, and
x3 to replace x0, x1, and x2.
Müller Method
Müller Method
Müller Method
Bairstow’s Method
• Bairstow’s method is an iterative approach loosely related to both Müller
and Newton Raphson methods.
• It is based on dividing a polynomial by a factor x-t:
f n ( x ) = ao + a1 x + a2 x 2 + + an x n
f n −1 ( x ) = b1 + b2 x + b3 x 2 + + bn x n
▪ with a reminder R = b0, the coefficients are calculated by recurrence
relationship
bn = an bi = a i +bi +1t i = n − 1 to 2
determine whether there is a remainder. If not, the guess was perfect and
the root is equal to t. If there is a remainder, the guess can be systematically adjusted
and the procedure repeated until the remainder disappears and a root is located. After
this is accomplished, the entire procedure can be repeated for the quotient to locate
another root.
Bairstow’s Method
• To permit the evaluation of complex roots, Bairstow’s method divides
▪ the polynomial by a quadratic factor x 2 − rx − s :
f n − 2 ( x ) = b2 + b3 x + + bn −1 x n −3 + bn x n − 2
R = b1 ( x − r ) + b0
bn = an
bn-1 = an-1 + rbn
bi = ai + rbi +1 + sbi + 2 i = n − 2 to 0
Bairstow’s Method
• For the remainder to be zero, b0 and b1 must be zero.
However, it is unlikely that our initial guesses at the
values of r and s will lead to this result, a systematic
approach can be used to modify our guesses so that b0
and b1 approach to zero.
• Using a similar approach to Newton Raphson method,
both b0 and b1 can be expanded as function of both r and
s in Taylor series.
Bairstow’s Method
b1 b
b1 ( r + r , s + s ) = b1 + r + 1 s
r s
b0 b
b0 ( r + r , s + s ) = b0 + r + 0 s
r s
Assuming that the initial guesses are adequately close to the values of r
and s at roots. The changes in s and r needed to improve our
guesses will be estimated as
b1 b
r + 1 s = −b1
r s
b0 b0
r + s = −b0
r s
Bairstow’s Method
If partial derivatives of the b’s can be determined, then the two equations can
be solved simultaneously for the two unknowns r and s .
Partial derivatives can be obtained by a synthetic division of the b’s in a similar
fashion to how the b’s themselves were derived:
cn = bn
cn −1 = bn −1 + rcn
ci = bi + rci +1 + sci + 2 i = n − 2 to 2
where
r
a, r = 100%
r
r
a, s = 100%
r
Bairstow’s Method
The values of the roots are determined by,
r r 2 + 4s
x=
2
At this point three possibilities exist:
1. The quotient is a third-order polynomial or greater. The previous values of r
and s serve as initial guesses and Bairstow’s method is applied to the quotient
to evaluate new r and s values.
2. The quotient is quadratic. The remaining two roots are evaluated directly,
using the above eqn.
3. The quotient is a 1st order polynomial. The remaining single root can be
evaluated simply as x = −s r .
Comparison of Root Finding Methods
Comparison of the characteristics of alternative methods for finding roots of algebraic and
transcendental equations. The comparisons are based on general experience and do not
account for the behavior of specific functions.
>> x=linspace(0,1,100);
>> y=x.^3-10*x.^2+5;
>> axis([0 1 0 5]);
>> plot(x,y)
MATLAB APPLICATIONS- increment search
function [x1,x2] = rootsearch(f, a, b, dx) >> rootsearch(inline('x^3-10*x^2+5', 'x'), 0, 1, 0.1)
x1= a;
f1= f(x1);
x2= a + dx;
f2= f(x2); 0.1000 4.9010
while f1*f2>0.0 0.2000 4.6080
if x1 >= b 0.3000 4.1270
x1= NaN; 0.4000 3.4640
x2= NaN; 0.5000 2.6250
return 0.6000 1.6160
end 0.7000 0.4430
x1= x2;
f1= f2; ans =
x2= x1 + dx;
f2= f(x2); 0.7000
disp([x1 f1])
end
MATLAB APPLICATIONS - bisection
MATLAB APPLICATIONS - bisection
function root = mybisect(f, x1, x2, filter, tol) n=ceil(log(abs(x2-x1)/tol)/log(2.0));
if nargin <5; for i=1:n
tol= 1.0e4*eps; xr=0.5*(x1+x2);
end fr=f(xr);
if nargin <4; if(filter ==1) & (abs(fr)>abs(f1)) & (abs(fr)>abs(f2))
filter= 0; root=NaN;
end return
f1= f(x1); end
if f1==0.0; if fr==0.0
root=x1; root=xr;
return; return
end end
f2=f(x2); if f2*fr<0
if f2==0.0; x1=xr;
root=x2; f1=fr;
return else
end x2=xr;
if f1*f2>0; f2=fr;
error('root is not in given interval') end
end root=(x1+x2)/2; end
>> mybisect(inline('x^3-10*x^2+5','x'), 0, 1, 1, 0.01)
ans =
0.7383
MATLAB APPLICATIONS – Newton Raphson
f ( xi )
xi +1 = xi −
f ( xi )
MATLAB APPLICATIONS – Newton Raphson
function [root, numIter] = mNewtonRaphson(f, df, x0, tol)
for i=1:30
dx=-f(x0)/df(x0);
x0=x0+dx;
if abs(dx)<tol
root=x0
numIter=i;
return
end
ans =
0.7346
MATLAB APPLICATIONS – Secant
xi − xi −1
xi +1 = xi − f ( xi ) i = 1, 2,3,
f ( xi ) − f ( xi −1 )
MATLAB APPLICATIONS – Secant
ans =
0.7429
Summary of Important Info in Part 2
PIPE FRICTION (Mechanical/Aerospace Eng.)
The Colebrook equation provides a means to calculate the friction factor for a pipe,
2.51
0 = + 2.0 log +
3.7 D Re f
f
where = the roughness ( m ) , D = diameter (m), and Re = the Reynolds number,
VD
Re =
1.325
f = 2
5.74
ln 3.7 D + Re0.9
PIPE FRICTION (Mechanical/Aerospace Eng.)
>> rho=1.23;mu=1.79e-5;D=0.005;V=40;e=0.0015/1000;
>> Re=rho*V*D/mu;
>> g=@(f) 1/sqrt(f)+2*log10(e/(3.7*D)+2.51/(Re*sqrt(f)));
>> fplot(g,[0.008 0.08]),grid,xlabel('f'),ylabel('g(f)')
PIPE FRICTION (Mechanical/Aerospace Eng.)
▪ Graphical method:
PIPE FRICTION (Mechanical/Aerospace Eng.)
>> rho=1.23;mu=1.79e-5;D=0.005;V=40;e=0.0015/1000;
>> Re=rho*V*D/mu
>> g=@(f) 1/sqrt(f)+2*log10(e/(3.7*D)+2.51/(Re*sqrt(f)));
>> fzero(g,0.008)
PIPE FRICTION (Mechanical/Aerospace Eng.)
Method Iterations Result Comments
Graphical 0.03
Bisection 22 0.0289678
Newton-Raphson 6 0.0289678 Needs good initial guess
MATLAB fzero 0.0289678 Needs good initial guess