You are on page 1of 48

O RDINARY DIFFERENTIAL EQUATION

E LECTRONIC LECTURE

January 22, 2021

Ordinary differential equation January 22, 2021 1 / 34


C ONTENT

1 C AUCHY PROBLEM

Ordinary differential equation January 22, 2021 2 / 34


C ONTENT

1 C AUCHY PROBLEM

2 S YSTEM OF DIFFERENTIAL EQUATIONS

Ordinary differential equation January 22, 2021 2 / 34


C ONTENT

1 C AUCHY PROBLEM

2 S YSTEM OF DIFFERENTIAL EQUATIONS

3 B OUNDARY PROBLEMS

Ordinary differential equation January 22, 2021 2 / 34


Cauchy problem Main problem

In this chapter, we concern about finding numerical


solution for ordinary differential equation

Ordinary differential equation January 22, 2021 3 / 34


Cauchy problem Main problem

In this chapter, we concern about finding numerical


solution for ordinary differential equation
½ 0
y (x) = f (x, y(x)), a É x É b,
. (1)
y(a) = y 0

Ordinary differential equation January 22, 2021 3 / 34


Cauchy problem Main problem

In this chapter, we concern about finding numerical


solution for ordinary differential equation
½ 0
y (x) = f (x, y(x)), a É x É b,
. (1)
y(a) = y 0

Where y(x) is continuous differential function on [a, b]


that we want to find.
The above problem is called Cauchy problem or initial
value problem.

Ordinary differential equation January 22, 2021 3 / 34


Cauchy problem Main problem

In general, we don’t have method to find exact


solution(analytical solution), except some special
cases(In calculus 1)

Ordinary differential equation January 22, 2021 4 / 34


Cauchy problem Main problem

In general, we don’t have method to find exact


solution(analytical solution), except some special
cases(In calculus 1)
So, the new approach is using numerical method to get
numerical solution, that is, we find approximate values of
y(x) at various values of x on [a, b]. And the approximate
values of y at other points can be found by interpolation.

Ordinary differential equation January 22, 2021 4 / 34


Cauchy problem Euler’s method

E ULER ’ S METHOD TO FIND APPROXIMATE SOLUTION OF


PROBLEM (1)

We divide [a, b] into n equally subintervals with step


b−a
h= , then the nodes are x 0 = a, x k = x 0 + kh.
n

Ordinary differential equation January 22, 2021 5 / 34


Cauchy problem Euler’s method

E ULER ’ S METHOD TO FIND APPROXIMATE SOLUTION OF


PROBLEM (1)

We divide [a, b] into n equally subintervals with step


b−a
h= , then the nodes are x 0 = a, x k = x 0 + kh.
n
Exact value of solution at x k is denoted by y(x k ),
approximate value is denoted by y k .

Ordinary differential equation January 22, 2021 5 / 34


Cauchy problem Euler’s method

E ULER ’ S METHOD TO FIND APPROXIMATE SOLUTION OF


PROBLEM (1)

We divide [a, b] into n equally subintervals with step


b−a
h= , then the nodes are x 0 = a, x k = x 0 + kh.
n
Exact value of solution at x k is denoted by y(x k ),
approximate value is denoted by y k .
Assume that y(x) is solution of problem (1), the
Taylor expansion of y(x) at x k is

(x k+1 − x k )2
y(x) = y(x k ) + y 0 (x k )(x − x k ) + y 00 (ξk ) ,
2
where ξk ∈ (x k , x k+1 ).
Ordinary differential equation January 22, 2021 5 / 34
Cauchy problem Euler’s method

E ULER ’ S METHOD TO FIND APPROXIMATE SOLUTION OF


PROBLEM (1)

We divide [a, b] into n equally subintervals with step


b−a
h= , then the nodes are x 0 = a, x k = x 0 + kh.
n
Exact value of solution at x k is denoted by y(x k ),
approximate value is denoted by y k .
Assume that y(x) is solution of problem (1), the
Taylor expansion of y(x) at x k is

(x k+1 − x k )2
y(x) = y(x k ) + y 0 (x k )(x − x k ) + y 00 (ξk ) ,
2
where ξk ∈ (x k , x k+1 ).
Ordinary differential equation January 22, 2021 5 / 34
Cauchy problem Euler’s method

Replace x k+1 into this equation


(x k+1 − x k )2
y(x k+1 ) = y(x k ) + y 0 (x k )(x k+1 − x k ) + y 00 (ξk ) ,
2
Since y = y(x) is solution of (1), so we have
y 0 (x k ) = f (x k , y k ) and h = x k+1 − x k , it yields that
h 2 00
y(x k+1 ) = y(x k ) + h. f (x k , y k ) + y (ξk ).
2

Ordinary differential equation January 22, 2021 6 / 34


Cauchy problem Euler’s method

Replace x k+1 into this equation


(x k+1 − x k )2
y(x k+1 ) = y(x k ) + y 0 (x k )(x k+1 − x k ) + y 00 (ξk ) ,
2
Since y = y(x) is solution of (1), so we have
y 0 (x k ) = f (x k , y k ) and h = x k+1 − x k , it yields that
h 2 00
y(x k+1 ) = y(x k ) + h. f (x k , y k ) + y (ξk ).
2
Truncating the error, we have Euler’s formula

y(x k+1 ) ≈ y k+1 = y k + h f (x k , y k ), k = 0, 1, 2, . . . , n − 1.

Ordinary differential equation January 22, 2021 6 / 34


Cauchy problem Euler’s method

G EOMETRIC INTERPRETATION

We draw the tangent line at x k , this line cut the line


x = x k+1 at y k+1 .
Ordinary differential equation January 22, 2021 7 / 34
Cauchy problem Euler’s method

E XAMPLE 1.1
Use Euler’s method to find approx. values of solution for
equation

y (x) = y − x 2 + 1, 0 É x É 2,
½ 0
.
y(0) = 0.5

with n = 10. The exact solution is

y(x) = (x + 1)2 − 0.5e x .

Compare the appox.solution and exact solution.

Ordinary differential equation January 22, 2021 8 / 34


Cauchy problem Euler’s method

Solution.
2−0
With n = 10 then h = = 0.2, x k = 0.2k, y 0 = 0.5. Euler’s
10
formula for appox.solution

y k+1 = y k + h(y k − x k2 + 1)

with k = 0, 1, . . . , 9.

Ordinary differential equation January 22, 2021 9 / 34


Cauchy problem Euler’s method

Solution.
2−0
With n = 10 then h = = 0.2, x k = 0.2k, y 0 = 0.5. Euler’s
10
formula for appox.solution

y k+1 = y k + h(y k − x k2 + 1)

with k = 0, 1, . . . , 9.
Using calculator. Y = Y + 0.2(Y − X 2 + 1) : X = X + 0.2
1 CALC Y = 0.5 =, X = 0 =
2 Y =, X = 0.2 =

Ordinary differential equation January 22, 2021 9 / 34


Cauchy problem Euler’s method

k xk yk y(x k ) |y(x k ) − y k |
0 0.0 0.5000000 0.5000000 0.0000000
1 0.2 0.8000000 0.8292986 0.0292986
2 0.4 1.1520000 1.2140877 0.0620877
3 0.6 1.5504000 1.6489406 0.0985406
4 0.8 1.9884800 2.1272295 0.1387495
5 1.0 2.4581760 2.6408591 0.1826831
6 1.2 2.9498112 3.1799415 0.2301303
7 1.4 3.4517734 3.7324000 0.2806266
8 1.6 3.9501281 4.2834838 0.3333557
9 1.8 4.4281538 4.8151763 0.3870225
10 2.0 4.8657845 5.3054720 0.4396874

Ordinary differential equation January 22, 2021 10 / 34


Cauchy problem Modified Euler’s method

M ODIFIED E ULER ’ S METHOD

Instead of using slope at x k , we replace it by arithmetic


average of slope over interval (x k , x k+1 ):

K 1k = h f (x k , y k )



K 2k = h f (x k + h, y k + K 1k )

k k
.

 y K 1 + K 2
k+1 = y k +

2

Ordinary differential equation January 22, 2021 11 / 34


Cauchy problem Modified Euler’s method

E XAMPLE 1.2
Using modified Euler’s formula to find approx values
solution for

y (x) = y − x 2 + 1, 0 É x É 2,
½ 0
.
y(0) = 0.5

with n = 10. Compares them to exact value, knowing that


exact solution is y(x) = (x + 1)2 − 0.5e x .

Ordinary differential equation January 22, 2021 12 / 34


Cauchy problem Modified Euler’s method

k xk yk y(x k ) |y(x k ) − y k |
0 0.0 0.5 0.5000000 0.0000000
1 0.2 0.826 0.8292986 0.0032986
2 0.4 1.20692 1.2140877 0.0071677
3 0.6 1.6372424 1.6489406 0.0116982
4 0.8 2.110235728 2.1272295 0.0169938
5 1.0 2.617687588 2.6408591 0.0231715
6 1.2 3.149578858 3.1799415 0.0303627
7 1.4 3.693686206 3.7324000 0.0387138
8 1.6 4.235097172 4.2834838 0.0483866
9 1.8 4.755618549 4.8151763 0.0595577
10 2.0 5.23305463 5.3054720 0.0724173

Ordinary differential equation January 22, 2021 13 / 34


Cauchy problem Runge-Kutta fourth order method

RUNGE -K UTTA FOURTH ORDER METHOD

Runge-Kutta fourth order method is more accurate than


Euler and modified Euler’s method because in Taylor
expansion, higher order derivatives were used.

y k+1 = y(x k + h) ≈ y k + 61 (K 1k + 2K 2k + 2K 3k + K 4k )



k
 K 1 = h f (x k , y k )



Kk

K 2k = h f (x k + h2 , y k + 21 ) .
 K k
K 3k = h f (x k + h2 , y k + 22 )





K 4k = h f (x k + h, y k + K 3k )

Ordinary differential equation January 22, 2021 14 / 34


Cauchy problem Runge-Kutta fourth order method

E XAMPLE 1.3
Using RK4 to evaluate approx values of solution at x = 0.2

y (x) = y − x 2 + 1, 0 É x É 2,
½ 0
.
y(0) = 0.5

with n = 10. Compare to exact solution


y(x) = (x + 1)2 − 0.5e x .

Ordinary differential equation January 22, 2021 15 / 34


Cauchy problem Runge-Kutta fourth order method

k xk yk y(x k ) |y(x k ) − y k |
0 0.0 0.5000000 0.5000000 0.0000000
1 0.2 0.8292933 0.8292986 0.0000053
2 0.4 1.2114362 1.2140877 0.0000114
3 0.6 1.6404175 1.6489406 0.0026515
4 0.8 2.1088953 2.1272295 0.0183342
5 1.0 2.6079021 2.6408591 0.032957
6 1.2 3.1264849 3.1799415 0.0000474
7 1.4 3.6512660 3.7324000 0.0000599
8 1.6 4.1659056 4.2834838 0.0000743
9 1.8 4.6504464 4.8151763 0.0000906
10 2.0 5.0805126 5.3054720 0.0001089

Ordinary differential equation January 22, 2021 16 / 34


System of differential equations

S YSTEM OF DIFFERENTIAL EQUATIONS

Consider system of differential equation




 x 0 (t ) = f (t , x(t ), y(t ))
 y 0 (t ) = g (t , x(t ), y(t ))

.

 x(t 0 ) = α
y(t 0 ) = β

With step size h, we need to compute approx solution


(x(t ), y(t )) at node t k = t 0 + kh. We denote:
x(t k ) ≈ x k , y(t k ) ≈ y k .

Ordinary differential equation January 22, 2021 17 / 34


System of differential equations Euler’s formula

E ULER ’ S FORMULA


 x(t k ) ≈ x k = x k−1 + h f (t k−1 , x k−1 , y k−1 )

y(t k ) ≈ y k = y k−1 + hg (t k−1 , x k−1 , y k−1 ) .

 k = 1, 2, . . . , n

Ordinary differential equation January 22, 2021 18 / 34


System of differential equations Modified Euler’s formula

M ODIFIED E ULER ’ S FORMULA



 K 1x = h f (t k−1 , x k−1 , y k−1 )
K 1y = hg (t k−1 , x k−1 , y k−1 )





K 2x = h f (t k−1 + h, x k−1 + K 1x , y k−1 + K 1y )




 K = hg (t
k−1 + h, x k−1 + K 1x , y k−1 + K 1y )

2y
1 .

 x(t k ) ≈ x k = x k−1 + (K 1x + K 2x )
2


1




 y(t k ) ≈ y k = y k−1 + (K 1y + K 2y )
2



k = 1, 2, . . . , n

Ordinary differential equation January 22, 2021 19 / 34


System of differential equations Modified Euler’s formula

E XAMPLE 2.1
Given system of differential equations


 x 0 (t ) = t x − 2y + 1
 y 0 (t ) = 2x + t y + sin t

, t Ê 1.

 x(1) = 0.25

y(1) = 0.75

Using Euler’s formula and modified Euler’s formula to


evaluate approx x(t ) and y(t ) at t = 1.2 with step h = 0.2.

Ordinary differential equation January 22, 2021 20 / 34


System of differential equations Initial value problem for second order differential equation

C AUCHY PROBLEM FOR SECOND ORDER DIFFERENTIAL


EQUATION

Consider the second order differential equation



00 0
 x (t ) = F (t , x(t ), x (t ))

x(t 0 ) = α t ∈ [t 0 , t 0 + H ]
 x 0 (t ) = β

0

Above equation can be transformed to system of


equations by letting y(t ) = x 0 (t )


 x 0 (t ) = f (t , x(t ), y(t )) = y
 y 0 (t ) = g (t , x(t ), y(t )) = F (t , x, y)


 x(t 0 ) = α
y(t 0 ) = β

Ordinary differential equation January 22, 2021 21 / 34


System of differential equations Initial value problem for second order differential equation

E XAMPLE 2.2
Given second order equation
x 00 − 2x 0 + 2x = e 2t . sin t , (0 < t < 1) with initial values
x(0) = −0.4, x 0 (0) = −0.6. Using Euler and modified Euler’s
method with step h = 0.1 to find approx value solution at
t = 0.2. Compare the results to exact values:
x(t ) = 0.2e 2t (sin t − 2 cos t ),
y(t ) = x 0 (t ) = 0.2e 2t (4 sin t − 3 cos t ).

Ordinary differential equation January 22, 2021 22 / 34


System of differential equations Initial value problem for second order differential equation

We let y(t ) = x 0 (t ), then the equation above is changed


into system


 x 0 (t ) = f (t , x(t ), y(t )) = y
 y 0 (t ) = g (t , x(t ), y(t )) = −2x + 2y + e 2t sin t


 x(0) = −0.4

y(0) = −0.6

with h = 0.1.

Ordinary differential equation January 22, 2021 23 / 34


System of differential equations Initial value problem for second order differential equation

tk x(t k ) xk x 0 (t k ) yk
0.0 −0.4000 −0.4000 −0.60000 −0.6000
0.1 −0.4617 −0.4617 −0.6316 −0.6316
0.2 −0.5256 −0.5256 −0.6401 −0.6401
0.3 −0.5886 −0.5886 −0.6136 −0.6136
0.4 −0.6466 −0.6466 −0.5366 −0.5366

Ordinary differential equation January 22, 2021 24 / 34


Boundary problems Motivation

B OUNDARY PROBLEMS FOR LINEAR SECOND ORDER ODE

In solving second order differential equation, if we


know y(x 0 ) and y 0 (x 0 ) we call that problem be initial
value problem.

Ordinary differential equation January 22, 2021 25 / 34


Boundary problems Motivation

B OUNDARY PROBLEMS FOR LINEAR SECOND ORDER ODE

In solving second order differential equation, if we


know y(x 0 ) and y 0 (x 0 ) we call that problem be initial
value problem.
However, many practical problems lead us to solve
2nd order differential equation in which we know the
values of solution at two different points(we know
y(a), y(b)). Those problems are called boundary
value problems.

Ordinary differential equation January 22, 2021 25 / 34


Boundary problems Motivation

EXAMPLE

Consider the deflection of a beam

Ordinary differential equation January 22, 2021 26 / 34


Boundary problems Motivation

EXAMPLE

Consider the deflection of a beam


w(x) is deflection at P, x is the distance from the left
end to the point.

Ordinary differential equation January 22, 2021 26 / 34


Boundary problems Motivation

EXAMPLE

Consider the deflection of a beam


w(x) is deflection at P, x is the distance from the left
end to the point.
The ends are supported so they undergo no
deflection.

Ordinary differential equation January 22, 2021 26 / 34


Boundary problems Motivation

The equation describes the deflection of the beam is


d 2w S qx
= w(x) + (x − l )
d x2 E I 2E I
where l , q, E , S and I represent, respectively, the length of
the beam, the intensity of the uniform load, the modulus
of elasticity, the stress at the endpoints, and the central
moment of inertia.
Since no deflection occurs at the ends of the beam, there
are two boundary conditions:

w(0) = 0, w(l ) = 0

Ordinary differential equation January 22, 2021 27 / 34


Boundary problems Motivation

We consider the boundary problem related to linear


second order differential equation

00 0
 p(x)y (x) + q(x)y (x) + r (x)y(x) = f (x),

a < x < b,
y(a) = α, y(b) = β.

with method called finite difference method.

Ordinary differential equation January 22, 2021 28 / 34


Boundary problems FINITE DIFFERENCE METHOD

Divide [a, b] equally into n subsintervals with step


size h: x 0 = a, x k = x 0 + kh, k = 1, 2, . . . , n − 1, x n = b
b−a
with h = .
n
At nodes x k , k = 1, 2, . . . , n − 1 inside interval [a, b] we
use centered difference formula, we have
y(x k+1 ) − y(x k−1 ) y k+1 − y k−1
y 0 (x k ) ≈ =
2h 2h
y(x k+1 ) − 2y(x k ) + y(x k−1 ) y k+1 − 2y k + y k−1
y 00 (x k ) ≈ =
h2 h2

Ordinary differential equation January 22, 2021 29 / 34


Boundary problems FINITE DIFFERENCE METHOD

Replace them into given equation, we have

y k+1 − 2y k + y k−1 y k+1 − y k−1


pk + q k + rk yk = fk ,
h2 2h
∀k = 1, 2, . . . , n − 1 where p k = p(x k ), q k = q(x k ), r k = r (x k )
and f k = f (x k ).

Ordinary differential equation January 22, 2021 30 / 34


Boundary problems FINITE DIFFERENCE METHOD

Replace them into given equation, we have

y k+1 − 2y k + y k−1 y k+1 − y k−1


pk + q k + rk yk = fk ,
h2 2h
∀k = 1, 2, . . . , n − 1 where p k = p(x k ), q k = q(x k ), r k = r (x k )
and f k = f (x k ).
From the boundary condition, y 0 = α, y n = β, we get
linear system equations with unknowns vector is
Y = (y 1 , y 2 , .., y n−1 ).

Ordinary differential equation January 22, 2021 30 / 34


Boundary problems FINITE DIFFERENCE METHOD

We solve Y from AY = B where A is matrix


2p 1 p1 q
 
r1 −h2 h2
+ 2h1 0 ... 0

 p 2 − q2 2p p2 q .. 
 h 2 2h r 2 − h 22 h2
+ 2h2 0 . 

 .. .. .. .. .. 

. . . . .

A=
 
.. .. 

 . ... ... ... . 

 .. .. p n−2 q n−2 2p p n−2 q


 . .
h2
− 2h r n−2 − hn−2
2 h2
n−2
+ 2h 

p n−1 q n−1 2p
0 0 ... h2
− 2h r n−1 − hn−1
2

p q
 
f 1 − ( h 21 − 2h1 )α
f2
 
 

B = .. 
.

 
f n−2
 
 
p n−1 q n−1
f n−1 − ( h2
+ 2h )β

Ordinary differential equation January 22, 2021 31 / 34


Boundary problems FINITE DIFFERENCE METHOD

T HE CASE n = 4

We solve Y = (y 1 , y 2 , y 3 ) in the system AY = B , where A is


tridiagonal matrix
2p 1 p 1 q 1
 
r 1 − h 2 h 2 + 2h 0 
p
 2 q2 2p 2 p 2 q 2 
A= 2 − r2 − 2 + .

h 2h h h 2 2h 
 p 3 q3 2p 3 
0 − r3 − 2
h 2 2h h
p q
 
f 1 − ( h 21 − 2h1 )α
B = f2 .
 
p3 q3
f 3 − ( h 2 + 2h )β
Ordinary differential equation January 22, 2021 32 / 34
Boundary problems FINITE DIFFERENCE METHOD

E XAMPLE 3.1
Given the linear boundary problem

2y(x)00 + (x + 1)y 0 (x) − y(x) = x 2 + x


½
.
y(0) = −0.3, y (1) = −0.1

Using the finite difference method to approximate y(x) on


the interval [0, 1] with step size h = 0.25.

Ordinary differential equation January 22, 2021 33 / 34


Boundary problems FINITE DIFFERENCE METHOD

THANK YOU FOR YOUR ATTENTION

Ordinary differential equation January 22, 2021 34 / 34

You might also like