Professional Documents
Culture Documents
Lecture Notes 2
Lecture Notes 2
Lecture Notes 2
1. Bracketing Methods
2. Open Methods
f(xu) f(x)
xl root
xu
f(xl)
mg t
c
v(t ) 1 e m
c
• Use the graphical approach to determine the mass
of the bungee jumper with a drag coefficient of
c=4 kg/m to have a velocity of v=36 m/s after t=4 s
of free fall. Note: The acceleration of gravity is
g=9.81 m/s2.
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
2.1.1 Graphical Methods
• If the given function equalize to zero:
mg t
c
m
f ( m) 1 e v 0
c
• The following MATLAB code sets up a plot of f(m) versus
mass
• c = 4; g = 9.81; v = 36; t = 4;
• m = 50:150;
• f = (m*g/c).*(1-exp(-c*t./m))-v;
• plot(m,f),grid
0.5
0
f(m)
-0.5
-1 Root
-1.5
-2
-2.5
50 60 70 80 90 100 110 120 130 140 150
m
• The function crosses the m axis between 90 and 95
kg
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
2.1.2 Bisection Method
0.5 mg
f ( m) 1
0
c
f(m)
-0.5
-1
Root
-1.5
-2
-2.5
50 60 70 80 90 100 110 120 130 140 150
xl m
xu
xl xu 1
xr 0.5
2 0
f(m )
-0.5
• xr is first estimation -1
-2
-2.5
50 60 70 80 90 100 110 120 130 140 150
xl m
xu
xr
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
2.1.2 Bisection Method
• Now the root is either between xl and xr (subinterval
1 ) or between xr and xu (subinterval 2).
1.5
0.5
0
f(m )
-0.5
-1
-1.5
-2
-2.5
50 60 70 80 90 100 110 120 130 140 150
xl m
xu
xr
Subinterval 1 Subinterval 2
• Otherwise (If f (xl )* f (xr) > 0) the root in subinterval 2 (between xr and
xu). Then xr is the new xl value.
a s
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
2.1.2 Bisection Method
• where;
new old
xr xr
a new
xr
xl xu
xr
2
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
2.1.2 Bisection Method
• Step3: Make the following evaluation to determine in
which subinterval the root lies.
i. If f (xl )* f (xr) < 0, the root lies in the subinterval
1(between [xl ,xr]). Therefore set xu=xr and return to
Step 2.
• Solution:
xl 1 xu 2 f (1) 5 f (2) 14
xl xu 1 2
xr 1.5 f ( xr ) f (1.5) 2.375
2 2
Approximate Error
xrnew xrold 1.25 1.5
a new
0.2 s
xr 1.25
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
Solution
Check
f ( xl ) f ( xr ) ( 5) (1.8) 9 0
Approximate Error
xrnew xrold 1.375 1.25
a new
0.09 s
xr 1.375
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
Solution
• New iteration
f ( xr ) f (1.375) 0.16
v (t ) 1 e m
c
68.1 9.81
c
68.1
10
40 1 e
c
• Then rearranging the equation
667.38
c
1 e 0.1468 c
40 0
14 16 f (15) 0.425
xr 15
2
• Check f (14) f (15) 1.565 (0.425) 0.665 0
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
15 14
a 100 6.667%
15
• The root between 14 and 15
• Step 3
14 15
xr 14.5
2
• Check f (14) f (14.5) (1.565) (0.5489) 0.8591 0
14.5 15
a 100 3.45%
14.5
• The root between 14.5 and 15
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
Iteration xl xu xr εa (%)
1 12 16 14 (14-12)/
14
2 14 16 15 6.67
3 14 15 14.5 3.45
4 14.5 15 14.75 1.70
5 14.75 15 14.875 0.84
6 14.75 14.875 14.8125 0.42
xr = (xl +xu)/2;
fxr = f(xr);
if fxl * fxr < 0
xu = xr;
fxu = fxr;
else
xl = xr; function [ y] = f( x )
fxl = fxr; y=(667.38/x)*(1-exp(-0.1468*x))-40;
end end
ea=abs((xr-xro)/xr);
iter=iter+1;
disp([iter,ea,xr])
end
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
Solution with Matlab
• enter your guess for lower bound=12
• enter your guess for upper bound=16
• enter relative error=0.005
• no of iteration root error
• 1.0000 0.1429 14.0000
f ( xl ) f ( xu )
xr xl xr xu
f ( xu )( xl xu )
xr xu
f ( xl ) f ( xu )
xl 12 f ( xl ) 6.067
xu 16 f ( xu ) 2.269
f ( xu )( xl xu ) 2.269(12 16)
xr xu 16 14.91
f ( xl ) f ( xu ) 6.067 (2.269)
• Second iteration
1.543
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
Solution
• Therefore the root between xl and xr
xl 12 f ( xl ) 6.067
xu 14.91 f ( xu ) 0.254
0.254(12 14.91)
xr 14.91 14.794
6.067 (0.254)
14.794 14.91
a 0.0079
14.794
x g ( x)
x2 2 x 3 0
x2 3
• Can be simply manupilated to yeild as: x
2
xi+1 = e−xi
• xn=0;
• es=1;
• ea=2*es;
• i=0;
• disp([' no root ea'])
• while es<ea
• x0=xn;
• xn=f(x0);
• ea=abs(((xn-x0)/xn)*100);
• i=i+1;
function [ y ] = f( x );
• disp([i xn ea])
y=exp(-x);
• end end
• No root Error
• 1 1 100
• 2.0000 0.3679 171.8282
• 3.0000 0.6922 46.8536
• 4.0000 0.5005 38.3091
• 5.0000 0.6062 17.4468
• 6.0000 0.5454 11.1566
• 7.0000 0.5796 5.9034
• 8.0000 0.5601 3.4809
• 9.0000 0.5711 1.9308
• 10.0000 0.5649 1.1089
3
xi 1
xi 2
xi 2 3
xi 1
2
a) g ( x) 2 x 3 g ( x) (2 x 3) 1/2
Substituting x=4
3
g (4) 2 0.75 1
2 Converging
c)
x2 3
g ( x)x=4
Substituting g ( x) x
2
g (4) 4 4 1
Diverging
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
Newton Raphson Method
• Perhaps the most widely used of all root-locating formulas
is the Newton-Raphson equation (Figure). If the initial
guess at the root is xi, a tangent can be extended from the
point [xi, f (xi)]. The point where this tangent crosses the x
axis usually represents an improved estimate of the root.
Newton Raphson
formula
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
Example
xn=0;
es=0.001;
ea=10;
i=1;
while es<ea function [ y ] = fd( x )
x0=xn; y=-exp(-x)-1;
end
xn=x0-f(x0)/fd(x0);
ea=abs((xn-x0)/xn);
disp([ i, xn, ea]) function [ y ] = f( x )
i=i+1; y=exp(-x)-x;
end end
• i root error
• 1.0000 0.5000 1.0000
• Solution
Newton Raphson Formula
The following equation can be used to compute the oxygen level c (mg/L)
in a river downstream from a sewage discharge:
c = 10 − 20(e−0.15x − e−0.5x )
Determine the distance downstream (x) where the oxygen level is c=5
mg/L. Use Newton Raphson Method, Develop a while loop to determine
your answer. (εs=0.01 x0=2) . Each step of iteration, calculate the root (xi)
and approximate error and write the given Table below. Prove your
answer plotting the function between 0<x<2.
es=0.001; 4
ea=10 3
i=0
2
disp([' no root ea'])
while es<ea 1
x0=xn; 0
xn=x0-f(x0)/fd(x0); -1
ea=abs(((xn-x0)/xn)); -2
i=i+1; -3
disp([ i xn ea]) 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
end
Number
function [ y ] = f( x )
of
y=5-20*(exp(-0.15*x)-exp(-0.5*x)); iteration xi εa
end 1 0.3117 5.4170
2 0.8434 0.6304
function [ y ] = fd( x ) 3 0.9699 0.1304
y=-20*(-0.15*exp(-0.15*x)+0.5*exp(-0.5*x)); 4 0.9762 0.0065
end CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
Secant Method
• A potential problem in the Newton-Raphson method is the
evaluation of the derivative. Because, there are certain
functions whose derivatives may be extremely difficult or
inconvenient to evaluate. For these cases, the derivative
can be approximated by a backward finite divided
difference, as:
f ( xi ) f ( xi 1 )
f ( xi )
xi xi 1
Secant Method
Formula
f ( x) 8sin( x)e x 1
• Solution
Secant Method
Formula
T WLc Lb / Lb 2 x 2 x 4
3
dT 1
(WLc Lb )( Lb 2 x 2 x 4 ) 2 (2 Lb 2 x 4 x 3 ) 0
dx 2
T WLc Lb / Lb 2 x 2 x 4
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
Solution
240
220
200
180
160
T (kN)
140
120
100
80 Minimum value
of Tension
60
1 1.5 2 2.5 3 3.5 4 4.5 5
x (m)
f ( xi xi ) f ( xi )
f ( xi )
xi