Numerical Solution of Ordinary Differential Equations Part 2 - Nonlinear Equations
Numerical Solution of Ordinary Differential Equations Part 2 - Nonlinear Equations
FACULTY OF ENGINEERING
Department of Engineering Sciences
Mathematical modelling of some engineering problems yields single and/or set of nonlinear
equations solution of which in most of the cases cannot be obtained by analytical methods. We
will first deal with the solution of single variable nonlinear equations. We have already shown at
the beginning of the previous lecture that solution of nonlinear single variable equation becomes
necessity to determine the value of the unknown. In the following we have illustrated some
examples of nonlinear single variable equations.
5 5
√(𝑥 − 31)/𝑥 + √𝑥 + 1 = 2
The values of 𝑥 that satisfies 𝑓(𝑥) = 0 are known as roots of the nonlinear equation. The number
of roots may be finite or infinite and may be real or complex depending on the nature of the
equation and the physical problem. The roots of nonlinear equation are also known as the zeros of
𝑓(𝑥) = 0 .
In page 53 to 58 of the textbook, there are examples of real engineering problems which require
determination of roots of nonlinear equations.
The available numerical methods for the solution of nonlinear equations can be collected in three
groups as listed below.
Numerical methods are based on step by step calculations which intends to approach to the solution
numerically. This means large amount of arithmetic calculation which is manually tedious work.
However, presence of computers makes this work feasible because of their fast and correct
computation power. Therefore, what was not worth mentioning as a method now can be used to
solve nonlinear equations. Graphical solution method is not practical to be used manually.
However, in MATLAB environment it becomes feasible which do not need deep computer
programming knowledge. We will introduce this facility in the following.
1
Incremental search method
In this method the value of 𝑥 is incremented from an arbitrarily selected initial value, say 𝑥 = 𝑥1
successively until a change takes place in the sign of 𝑓(𝑥). The idea is that 𝑓(𝑥) changes sign
between 𝑥𝑖 and 𝑥𝑖+1if it has a root in the interval [𝑥𝑖 , 𝑥𝑖+1 ] as shown in the following figure. This
implies that 𝑓(𝑥𝑖 )𝑓(𝑥𝑖+1 ) < 0 whenever a root is crossed.
2
Example 1:
Increasing accuracy:
3
We could execute the above calculations in MATLAB by writing the following simple program.
x=0:0.1:0.7;
y=4.905*x.^2-15*x+5;
disp (' x y')
for i=1:length(x)
fprintf('%6.4f %10.4f\n', x(i), y(i))
end
The output will be as follows which the same as the first table above is:
x y
0.0000 5.0000
0.1000 3.5491
0.2000 2.1962
0.3000 0.9414
0.4000 -0.2152
0.5000 -1.2737
0.6000 -2.2342
0.7000 -3.0966
The other tables can be obtained in a similar manner by just changing the limits and increment
values in x array given in the first line of the program.
We can use plot function of MATLAB to carry out the following example in a shorter way.
x=0:0.01:1;
y=4.905*x.^2-15*x+5;
plot(x,y); grid
By checking the point at which the graph intersects the x axis one can find the root. To get the
numerical value of the root ginput command can be used.
4
x=0:0.01:1;
y=4.905*x.^2-15*x+5;
plot(x,y); grid
ginput
ginput command brings two orthogonal lines on the graph. By coinciding this plus sign with the
intersection point and then pressing “enter” gives the values of the intersection point which is the
root on the command window of MATLAB as given below.
ans =
0.3821 -0.0140
What it gives is the coordinates of the intersection point. Because we are unable to coincide it
exactly on the intersection point, we get y value which is supposed to be zero. However, the x
value is the approximate root.
Simple mathematical modelling of a falling parachutist shown in the figure below necessitates use
of Newton’s second law. 𝐹 = 𝑚𝑎 where F is the net force acting on the body, m is the mass of the
object and a is its acceleration. From which the acceleration can be expressed as 𝑎 = 𝐹/𝑚.
Noticing the fact that the acceleration is the change of the velocity with time, it follows
𝑑𝑣 𝐹
= where v is velocity and t is time. The net force on the body is 𝐹 = 𝐹𝐷 − 𝐹𝑈 in which
𝑑𝑡 𝑚
5
𝐹𝐷 = 𝑚𝑔 where g is gravitational acceleration. If the air resistance can
simply be written as proportional to the velocity, then 𝐹𝑈 = −𝑐𝑣 where
c is called drag coefficient. Substituting these expressions into the
𝑑𝑣 𝑚𝑔−𝑐𝑣
differential equation, it follows = which can be
𝑑𝑡 𝑚
simplified into
𝑑𝑣 𝑐
=𝑔− 𝑣
𝑑𝑡 𝑚
𝑔𝑚
𝑣(𝑡) = (1 − 𝑒 −𝑐𝑡/𝑚 ) (1)
𝑐
When we consider a parachutist of mass 68.1kg jumps out of stationary hot air balloon with drag
coefficient equal to 12.5 kg/s then the above expression takes the following form.
9.8 × 68.1
𝑣(𝑡) = (1 − 𝑒 −12.5𝑡/68.1 ) = 53.39(1 − 𝑒 −0.18355𝑡 )
12.5
Which can be used to compute the velocity at any time after the jump. This is the exact solution
of the above problem.
When the above problem is changed to calculate the drag coefficient c needed for a parachutist
of mass m=68.1kg to have a velocity of 40m/s after free-falling for time t=10s, we end up with
the following nonlinear equation. Going back to eqn. (1) and substituting the above values of
known parameters, it follows
9.8×68.1
40 = (1 − 𝑒 −10𝑡/68.1 )
𝑐
Which can be simplified to
667.38
𝑓(𝑐) = (1 − 𝑒−0.146843𝑐 ) − 40 = 0
𝑐
The root of the above equation gives the value of the drag coefficient. We can obtain the root by
using graphical solution. The following MATLAB code plots the variation of f(c) with respect to
t.
x=0.1:0.1:20;
y=667.8*(1-exp(-0.146843*x))./x-40;
plot(x,y)
grid
ginput
6
ans =
14.6777 -0.1051
Example 3:
1.1288
Determine the root of tanh(1.3288 h ) by graphical method.
h
h=0.1:0.1:5;
sh=sqrt(h);
y1=1.1288./sh;
y2=tanh(1.3288*sh);
plot(h,y1,h,y2)
grid
ginput
7
y1, y2
1.1288
𝑦1 =
√ℎ
h=1.45m
𝑦2 = tanh(1.3288√ℎ)
We can plot two curves y1 = ( - sin ())/2 and y2 = A/r2 and look
for their intersection. The following MATLAB statements will find
the value of Φ for r=2m, area=0.0472m2.
8
r=2; area=0.0472;
phi=0:pi/360:pi/4;
x=180*phi/pi;
y1=(phi-sin(phi))/2;
y2=area/r^2*ones(size(y1));
plot(x,y1,x,y2),grid
xlabel(' angle at center, phi, degrees')
gtext('(phi-sin(phi))/2')
gtext(' area/r^2')
[phi0 y0]= ginput(1)
9
BRACKETTING METHODS
Bi-section method:
10
11
12
Example:
13
MATLAB APPLICATION OF BI-SECTION METHOD
function y= parach(x)
y=667.38*(1-exp(-0.146843*x))/x-40;
iter xl xu xr fl fr ea
1.0000 12.0000 16.0000 14.0000 6.0669 1.5687 0.1429
2.0000 14.0000 16.0000 15.0000 1.5687 -0.4248 0.0667
3.0000 14.0000 15.0000 14.5000 1.5687 0.5523 0.0345
4.0000 14.5000 15.0000 14.7500 0.5523 0.0590 0.0169
5.0000 14.7500 15.0000 14.8750 0.0590 -0.1841 0.0084
6.0000 14.7500 14.8750 14.8125 0.0590 -0.0629 0.0042
7.0000 14.7500 14.8125 14.7813 0.0590 -0.0020 0.0021
8.0000 14.7500 14.7813 14.7656 0.0590 0.0284 0.0011
9.0000 14.7656 14.7813 14.7734 0.0284 0.0132 0.0005
number of iterations= 9
root= 14.7734
15
REGULA FALSI METHOD
16
17
Example: Find the root of 𝑓(𝑥) = 4.905𝑥 2 − 15𝑥 + 5 = 0 within the interval 𝑥𝑙 = 0.3 𝑎𝑛𝑑 𝑥𝑢 =
0.4 with ε<5×10-4.
Example: Find a root of an equation f(x)=2x3-2x-5 using False Position method (regula falsi
method)
Solution:
2x3-2x-5=0 is the equation for which the root is to be found. Let f(x)=2x3-2x-5. Compute the values of
function for x=0, 1, 2
x 0 1 2
f(x) -5 -5 7
1st iteration : f(1)=-5<0 and f(2)=7>0 ∴ Now, Root lies between x0=1 and x1=2
( ) ( ) ( ),
x2=x0-f x0 ⋅x1-x0f x1 -f x0 x2=1-(-5)⋅2-17-(-5), x2=1.41667
( )
f x2 =f(1.41667)=2⋅1.416673-2⋅1.41667-5=-2.14699<0
18
2nd iteration : f(1.41667)=-2.14699<0 and f(2)=7>0, ∴ Now, Root lies between x0=1.41667 and x1=2
( ) ( ) ( ), x3=1.41667-(-2.14699)⋅2-1.416677-(-2.14699)=1.55359
x3=x0-f x0 ⋅x1-x0f x1 -f x0
( )
f x3 =f(1.55359)=2⋅1.553593-2⋅1.55359-5=-0.60759<0
3rd iteration : f(1.55359)=-0.60759<0 and f(2)=7>0,∴ Now, Root lies between x0=1.55359 and x1=2
( ) ( ) ( ), x4=1.55359-(-0.60759)⋅2-1.553597-(-0.60759)=1.58924
x4=x0-f x0 ⋅x1-x0f x1 -f x0
( )
f x4 =f(1.58924)=2⋅1.589243-2⋅1.58924-5=-0.15063<0
4th iteration : f(1.58924)=-0.15063<0 and f(2)=7>0, ∴ Now, Root lies between x0=1.58924 and x1=2
( ) ( ) ( ),x5=1.58924-(-0.15063)⋅2-1.589247-(-0.15063)=1.59789
x5=x0-f x0 ⋅x1-x0f x1 -f x0
( )
f x5 =f(1.59789)=2⋅1.597893-2⋅1.59789-5=-0.0361<0
5th iteration : f(1.59789)=-0.0361<0 and f(2)=7>0, ∴ Now, Root lies between x0=1.59789 and x1=2
( ) ( ) ( ), x6=1.59789-(-0.0361)⋅2-1.597897-(-0.0361)=1.59996
x6=x0-f x0 ⋅x1-x0f x1 -f x0
( )
f x6 =f(1.59996)=2⋅1.599963-2⋅1.59996-5=-0.00858<0
6th iteration : f(1.59996)=-0.00858<0 and f(2)=7>0, ∴ Now, Root lies between x0=1.59996 and x1=2
( ) ( ) ( ), x7=1.59996-(-0.00858)⋅2-1.599967-(-0.00858)=1.60045
x7=x0-f x0 ⋅x1-x0f x1 -f x0
( )
f x7 =f(1.60045)=2⋅1.600453-2⋅1.60045-5=-0.00203<0
7th iteration : f(1.60045)=-0.00203<0 and f(2)=7>0, ∴ Now, Root lies between x0=1.60045 and x1=2
( ) ( ) ( ), x8=1.60045-(-0.00203)⋅2-1.600457-(-0.00203)=1.60056
x8=x0-f x0 ⋅x1-x0f x1 -f x0
( )
f x8 =f(1.60056)=2⋅1.600563-2⋅1.60056-5=-0.00048<0
Approximate root of the equation 2x3-2x-5=0 using False Position method is 1.60056. Complete
calculations are given in the following table.
19
Open Methods
20
Algorithm - Fixed Point Iteration Scheme
In this case g1(x) = 10 / (x3-1) and the fixed point iterative scheme xi+1=10 / (xi3 -1), i = 0, 1, 2,..
let the initial guess x0 be 2.0
i 0 1 2 3 4 5 6 7 8
xi 2 1.429 5.214 0.071 -10.004 -9.978E-3 -10 -9.99E-3 -10
So the iterative process with g1 gone into an infinite loop without converging.
Another re-arrangement can be x4 =x+10, x = (x+10)1/4 , In this case g2(x) = (x + 10)1/4 and
the fixed point iterative scheme
xi+1= (xi + 10)1/4, i = 0, 1, 2, . . .
i 0 1 2 3 4 5 6
xi 1.0 1.82116 1.85424 1.85553 1.85558 1.85558
xi 2.0 1.861 1.8558 1.85559 1.85558 1.85558
xi 4.0 1.93434 1.85866 1.8557 1.85559 1.85558 1.85558
That is for g2 the iterative process is converging to 1.85558 with any initial guess.
In this case g3(x) =(x+10)1/2/x and the fixed point iterative scheme
21
xi+1=( xi+10)1/2 /xi, i = 0, 1, 2, . . .
i 0 1 2 3 4 5 6 ... 98
xi 1.8 1.9084 1.80825 1.90035 1.81529 1,89355 1.82129 . . . 1.8555
That is for g3 with any initial guess the iterative process is converging but very slowly to
The graphs in Fig g1, Fig g2 and Fig g3 demonstrates the Fixed point Iterative Scheme with g1,
g2 and g3 respectively for some initial approximations. It's clear from the
Fig g1, the iterative process does not converge for any initial approximation.
Fig g2, the iterative process converges very quickly to the root which is the intersection point
of y = x and y = g2(x) as shown in the figure.
Fig g3, the iterative process converges but very slowly.
i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 ... 31 32
xi 1 0.199 0.803 0.311 0.698 0.381 0.634 0.427 0.594 0.458 0.567 0.478 0.551 0.491 ... 0.518 0.518
22
Example 3: Find the root of x-exp[-x] = 0
i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
xi 3.0 0.05 0.951 0.386 0.68 0.507 0.602 0.548 0.578 0.561 0.571 0.565 0.568 0.567 0.567
i 0 1 2 3 4 5 6
xi -2 -1.227 -0.776 -0.603 -0.58 -0.579 -0.679
Example 5:
1.5𝑥 −1
1 0.65𝑥
= 0.65𝑡𝑎𝑛 ( ) −
(1 + 𝑥 2 )2 𝑥 (1 + 𝑥 2 )
13 1 13
Which in turn can be written as 𝑥 = (1 + 𝑥 2 )2 𝑡𝑎𝑛−1 ( ) − 𝑥(1 + 𝑥 2 )
30 𝑥 30
23
FIXED POINT ITERATION METHOD Prof. M. P. Saka
ALGORITHM:
1. Choose x1 as initial guess for the root.
2. Calculate the new root in each iteration i as x i 1 g ( x i ) ,
3. Terminate calculations when a s .
24
xn=g(x0);
iter=iter+1;
if xn ~=0
ea=abs((xn-x0)/xn);
end
disp([iter xn ea])
end
disp('number of iterations=')
disp(iter)
disp('root is equal to')
disp(xn)
function y= g(x)
y=exp(-x)
Program is run to determine the root of equation 𝑥 − 𝑒 −𝑥 = 0. The form selected for the method
is 𝑥 = 𝑒 −𝑥 which yields 𝑔(𝑥) = 𝑒 −𝑥 .
25
Newton Raphson method
The Newton-Raphson method is well-known and most powerful method used for finding the root
of the equation f(x)=0. It can be derived by using Taylor’s series expansion of the function f(x)
about an arbitrary point x0 as
26
27
Example 1:
Example 2:
28
Newton -Raphson method may not converge to a solution as shown in the following figure.
These difficulties can be corrected by starting from a new initial guess point.
29
30
MATLAB Program for Newton-Raphson Method
disp([iter,xo,f,fd,xn,ea])
if iter > imax
disp(' maximum number of iterations is reached')
break
end
end
disp('number of iterations=')
disp(iter)
disp( 'root=')
disp(xn)
OUTPUT:
enter your guess for the root=1
enter relative error=0.001
enter the maximum number of iterations=25
iter xo f fd xn ea
1.0000 1.0000 0.5522 -2.4624 1.2243 0.1832
2.0000 1.2243 0.1509 -1.1779 1.3524 0.0948
3.0000 1.3524 0.0393 -0.5770 1.4205 0.0479
4.0000 1.4205 0.0100 -0.2857 1.4556 0.0241
5.0000 1.4556 0.0025 -0.1425 1.4733 0.0120
6.0000 1.4733 0.0006 -0.0718 1.4820 0.0059
7.0000 1.4820 0.0002 -0.0373 1.4861 0.0027
8.0000 1.4861 0.0000 -0.0215 1.4876 0.0010
9.0000 1.4876 0.0000 -0.0156 1.4879 0.0002
number of iterations= 9
root= 1.4879
31
Secant method
32
33
34
COMPARISON OF CONVERGENCE OF THE SECANT AND FALSE POSITION
METHOD
Use the false-position and secant methods to estimate the root off ( x) ln( x) . Start the
computation with values of xl xi 1 0.5 and xu xi 5.0 .
number of iterations= 7
root= 1.0003
35
COMPARISON OF DIFFERENT METHODS FOR SOLVING A NONLINEAR
EQUATION
x
Let us estimate the root of f ( x) e x using Newton-Raphson, Bi-section, False position,
Secant and fixed point-iterations methods with an initial guess of xo= 0.
1) Newton-Raphson Method
2) Bi-section method
36
iter xl xu xr f (x l) f (x u) f (x r)
1.0000 -1.0000 1.0000 0.7094 3.7183 -0.6321 -0.2175
2.0000 -1.0000 0.7094 0.6149 3.7183 -0.2175 -0.0743
3.0000 -1.0000 0.6149 0.5833 3.7183 -0.0743 -0.0253
4.0000 -1.0000 0.5833 0.5726 3.7183 -0.0253 -0.0086
5.0000 -1.0000 0.5726 0.5690 3.7183 -0.0086 -0.0029
6.0000 -1.0000 0.5690 0.5678 3.7183 -0.0029 -0.0010
7.0000 -1.0000 0.5678 0.5674 3.7183 -0.0010 -0.0003
4) Secant Method
z=fzero(‘function’,xo) finds a zero of the function f(x) that is near to xo. fzero identifies only
points where the function actually crosses the x-axis. Points where the function touches the x-axis,
but does not cross it are not considered zeros.
EXAMPLE 1: To find the zero of the function f(x) = x 3 – 2 x – 5 , first we have to write an M-
file as shown in the following and save it as f.m in a directory of your selection.
function y=f(x)
y=x.^3-2*x-5
Then by just typing the following in the command window the root will appear on the screen in
no time.
z = fzero(‘f’, 2)
z=
2.0946
EXAMPLE 2: Determine the root of f ( x)
667.38
x
1 e 0.146843x 40 .
Prepare Matlab function and save it as parachuter.m file.
function y=parachuter(x)
f=667.8*(1-exp(-0.146843*x))./x-40
Then type the following in the command window to determine the root of the nonlinear equation.
root = fzero('parachuter',10)
press “enter” and you will see the following output on the command window.
root =
14.7802
38