0% found this document useful (0 votes)
30 views

C8

1. Three numerical methods are discussed for solving ordinary differential equations: Euler's method, improved Euler's method, and the Runge-Kutta method. 2. For first-order differential equations, these methods approximate the solution by discretizing the interval and using Taylor expansions. 3. For second-order boundary value problems, the finite difference method uses Taylor expansions to approximate derivatives and transform the equation into a system of linear equations.

Uploaded by

Denis Garrix
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

C8

1. Three numerical methods are discussed for solving ordinary differential equations: Euler's method, improved Euler's method, and the Runge-Kutta method. 2. For first-order differential equations, these methods approximate the solution by discretizing the interval and using Taylor expansions. 3. For second-order boundary value problems, the finite difference method uses Taylor expansions to approximate derivatives and transform the equation into a system of linear equations.

Uploaded by

Denis Garrix
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Numerical methods for solving ordinary

differential equations
Some methods will be discussed in this course:

For first-order differential equations given the initial condi-


tion, for example:
y ′ (x) = x3 − x y (x) + y 2 (x) , x ∈ (0, 1) ,
{
y (0) = 5.3,
we discuss here three methods to obtain approximate solutions:
• Euler’s method.
• Improved Euler’s method.
• Runge-Kutta method.

For the linear second-order boundary-value problem, for ex-


ample:
x3 y” (x) − x y ′ (x) + 2 y (x) = x2, x ∈ (0, 2) ,
{
y (0) = 0.3, y (2) = 1.2,
we consider:
• The finite-difference method.

All methods here are based on the same technique:


using Taylor expansion.

1
Example. Let y (x) be a function satisfying
2
y ′ (x) = x3 − x y (x) + (y (x)) , x ∈ (0, 1) ,
(⋆) {
y (0) = 2.2.
Find an approximation for y (0.1).
There are three methods discussed here:
• Euler’s method.
• Improved Euler’s method.
• Runge-Kutta method.

For simplicity, the equation (⋆) can be written as


y ′ (x) = f (x, y (x)) , x ∈ (0, 1) ,
{
y (0) = 2.2.
Here
f (s, t) ∶= s3 − st + t2.

First, let’s divide the interval [0, 1] into 10 equal intervals, so


the step size is h = 0.1.

x0 x1 x2 x3 x10

0.1

2
Euler’s method.

y (0.1) = y (x1) = y (x0 + h)

(First-order Taylor expansion) ≈ y (x0) + h y ′ (x0)

≈ 2.2 + 0.1 f (0, 2.2)

≈ 2.6840 .

We can continue this process to find approximate values for


y (0.2), y (0.3) , . . .:

y (0.2) = y (x2)

≈ y (x1) + h f (x1, y (x1))

≈ 2.6840 + 0.1 f (0.1, 2.6840)

≈ 3.3777.

3
Euler’s method.

Given the equation:


y ′ (x) = f (x, y (x)) , x ∈ (a, b) ,
{
y (a) = α.

Consider the Euler’s method with step size h, that is


x0 ∶= a, x1 = x0 + h, . . . , xk = x0 + hk, . . .

Define the sequence {yk } by:


y0 = α,
{
yk+1 = yk + h f (xk , yk ) , for k ≥ 0.

Then we have the approximation:


y (xk ) ≈ yk

Example. Let y (x) be a function satisfying


2
y ′ (x) = x3 − x y (x) + (y (x)) , x ∈ (0, 1) ,
{
y (0) = 2.2.
Use the Euler’s method with step size h = 0.1 to find an
approximation for y (0.5).

4
Answer.
y (0.5) ≈ 10.0294

Implementation:

Y = Y + 0.1 (X 3 − XY + Y 2) ∶ X = X + 0.1

5
Improved Euler’s method
The idea of the improved Euler’s method: instead of using
first-order Taylor expansion, we consider second-order Taylor
expansion:
Example. Let y (x) be a function satisfying
2
y ′ (x) = x3 − x y (x) + (y (x)) , x ∈ (0, 1) ,
(⋆) {
y (0) = 2.2.
Find an approximation for y (0.1).

Improved Euler’s method:


Assume that the step size is h = 0.1, then

y (0.1) = y (x1) = y (x0 + h)

′ 1 2
≈ y (x0) + hy (x0) + h y” (x0)
2

f (x0, y (x0)) + f (x1, y0 + hf (x0, y (x0)))


≈ y (x0) + h
2

f (0, 2.2) + f (0.1, 2.2 + 0.1 f (0, 2.2))


≈ 2.2 + 0.1
2

≈ 2.7888.
6
Improved Euler’s method.

Given the equation:


y ′ (x) = f (x, y (x)) , x ∈ (a, b) ,
{
y (a) = α.

Consider the improved Euler’s method with step size h,


that is
x0 ∶= a, x1 = x0 + h, . . . , xk = x0 + hk, . . .

Define the sequence {yk } by:



⎪y0

⎪ = α,
⎨ f (xk , yk ) + f (xk+1, yk + h f (xk , yk ))


⎪ yk+1 = yk + h , for k ≥ 0.
⎩ 2

Then we have the approximation:


y (xk ) ≈ yk

Example. Let y (x) be a function satisfying


2
y ′ (x) = x3 − x y (x) + (y (x)) , x ∈ (0, 1) ,
{
y (0) = 2.2.
Use the improved Euler’s method with step size h = 0.1 to
find an approximation for y (0.5).
7
Answer.
y (0.5) ≈ 39.5783

Implementation:

A = X + 0.1 ∶ B = Y + 0.1 (X 3 − XY + Y 2) ∶
0.1
Y =Y + (X 3 − XY + Y 2 + A3 − AB + B 2) ∶ X = A
2

8
Runge-Kutta method.

Given the equation:


y ′ (x) = f (x, y (x)) , x ∈ (a, b) ,
{
y (a) = α.

Consider the Runge-Kutta method with step size h,


that is
x0 ∶= a, x1 = x0 + h, . . . , xk = x0 + hk, . . .

Define the sequence {yk } by:



⎪y0
⎪ = α,
⎨ 1

⎪ y k +1 = y k + (Ak + 2Bk + 2Ck + Dk ) , for k ≥ 0,
⎩ 6
where
Ak ∶= h f (xk , yk ) ,

h Ak
Bk ∶= h f (xk + , yk + ) ,
2 2

h Bk
Ck ∶= h f (xk + , yk + ) ,
2 2

Dk ∶= h f (xk + h, yk + Ck ) .

Then we have the approximation:


y (xk ) ≈ yk
9
Idea behind the Runge-Kutta formula: similar to the Euler’s
method or the improved Euler’s method, we also apply the Tay-
lor expansion. However, for the Runge-Kutta method, we use
Taylor expansion of order 4.

Example. Let y (x) be a function satisfying


y ′ (x) = sin (x) + x2 y (x) , x ∈ (1, 3) ,
{
y (1) = 0.3.
Use the Runge-Kutta method with step size h = 0.1 to
find an approximation for y (1.1).

10
Answer.

h = 0.1, x0 = 1, y0 = 0.3, f (x, y ) = sin (x) + x2y.


Since y (1.1) = y (x1) ≈ y1, therefore our objective is to
find y1.
We have
1
y1 = y0 + (A0 + 2B0 + 2C0 + D0)
6

A0 = h f (x0, y0) = 0.1 f (1, 0.3) → STO A,


h A0 0.1 A
B0 = h f (x0 + , y0 + ) = 0.1 f (1 + , 0.3 + ) → STO B,
2 2 2 2
h B0 0.1 B
C0 = h f (x0 + , y0 + ) = 0.1 f (1 + , 0.3 + ) → STO C,
2 2 2 2
D0 = h f (x0 + h, y0 + C0) = 0.1 f (1 + 0.1, 0.3 + C ) → STO D.

Thus
1
y1 = 0.3 + (A + 2B + 2C + D) = 0.4268.
6

11
Linear second-order boundary-value problem:

p (x) y” (x) + q (x) y ′ (x) + r (x) y (x) = f (x) , a < x < b,


{
y (0) = α, y (b) = β.

• The method: the finite-difference method (the behind idea


is still Taylor expansion).
• We use Taylor expansion to approximate the derivatives: y ′,
y”. In the end, we transfer the differential equation into a
system of linear equations.

Assume that the step size is h.

x0 x1 x2 x3 ⋯ xn

First, let’s approximate y ′ (xk ) and y” (xk ):


y (xk+1) = y (xk + h) ≈ y (xk ) + hy ′ (xk ) (Taylor expansion) ,
y (xk−1) = y (xk − h) ≈ y (xk ) − hy ′ (xk ) (Taylor expansion) .

12

y (xk+1) − y (xk−1)
y ′ (xk ) ≈ (that’s why we call this method:
2h
finite-difference method).

Similarly, let’s use Taylor expansion of order 2 to approxi-


mate y” (xk ):
1
y (xk+1) = y (xk + h) ≈ y (xk ) + hy ′ (xk ) + h2y” (xk ) ,
2
′ 1 2
y (xk−1) = y (xk − h) ≈ y (xk ) − hy (xk ) + h y” (xk ) .
2

y (xk+1) − 2y (xk ) + y (xk−1)


y” (xk ) ≈ 2
.
h

For simplicity, let’s denote yk for y (xk ).


Also, pk for p (xk ), qk for q (xk ), rk for r (xk ), and fk for f (xk ).
It’s time to insert our approximations into the equation, we
get that:

13
yk+1 − 2yk + yk−1 yk+1 − yk−1
pk 2
+ q k + rk yk ≈ fk .
h 2h

This is equivalent to:

p k qk 2pk p k qk
( 2 − ) yk−1+(rk − 2 ) yk +( 2 + ) yk+1 ≈ fk , 1 ≤ k ≤ n−1.
h 2h h h 2h

Remember that we also have the boundary conditions:


y0 = α, yn = β.
From here we arrive that a system of n − 1 equations with n − 1
unknowns: y1, y2, . . . , yn−1:


⎪ pk qk 2pk p k qk


⎪ ( 2 − ) yk−1 + (rk − 2 ) yk + ( 2 + ) yk+1 ≈ fk ,
⎪ h 2h

⎪ h h 2h
1 ≤ k ≤ n − 1,







⎩y0 = α, yn = β.

Remark. Even though this is not a real system (since we


have the approximate signs here, not the equal signs), however,
solving this system would give you approximation values for
y (xk ), that is
y (xk ) ≈ yk .

14
Example. Consider the linear second-order boundary-value
problem:
(x + 0.23) y” + x2y ′ − 1.23 y = 0.29x (x + 2) , 1 < x < 1.8,
{
y (1) = 0.27, y (1.8) = 1.67.
Use the finite-difference method with step size h = 0.2 to
approximate the values of y (1.2) , y (1.4) , y (1.6).
Answer. We have

p (x) = x + 0.23, q (x) = x2, r (x) = −1.23,


f (x) = 0.29x (x + 2) .

α = 0.27, β = 1.67, h = 0.2,

x0 = 1, x1 = 1.2, x2 = 1.4, x3 = 1.6 , x4 = 1.8.

Objective Find y1, y2, y3 by solving the system:


⎡ r − 2p21 p12 + q1 0 RRR f − α ( p1 − q1 ) ⎤
⎢ 1 h h 2h R 1 h2 2h ⎥
⎢ p2 q2 2p2 p2 q2 RRR ⎥
⎢ h2 − 2h r2 − h2 h2 + 2h RR f2 ⎥.
⎢ p3 q3 2p3 R R p 3 q 3

⎢ 0
⎣ h2
− 2h r3 − h2 RRR f3 − β ( h2 + 2h ) ⎥⎦
Here
pk = p (xk ) , rk = r (xk ) , qk = q (xk ) , fk = f (xk ) .
We get that
y1 = 0.6504, y2 = 1.0100, y3 = 1.3498.
15
Therefore
y (1.2) ≈ 0.6504, y (1.4) ≈ 1.0100, y (1.6) ≈ 1.3498.

16
Exercise.
1. Consider the Cauchy equation:
y ′ (x) = x2 + x y 3, x > 1,
{
y (1) = 0.7.

Use the Euler’s method with step size h = 0.2 to find an ap-
proximation for y (1.8).
2. Consider the Cauchy equation:
y ′ (x) = sin (x) + x2 y, x > 1,
{
y (1) = 0.3.

Use the improved Euler’s method with step size h = 0.1 to


find an approximation for y (2.0).
3. Consider the Cauchy equation:
y ′ (x) = y 2 + x3 y, x > 1,
{
y (1) = 0.7.

Use the Runge-Kutta method with step size h = 0.2 to find an


approximation for y (1.2).
4. Consider the linear second-order boundary-value problem:
(x2 + 1) y” + 5x y ′ − 10 y = −8x2, 1.4 < x < 1.8,
{
y (1.4) = 0, y (1.8) = 0.8.

Use the finite-difference method with step size h = 0.1 to ap-


proximate the values of y (1.5) , y (1.6) , y (1.7).

17
Answer.
1. y (1.8) ≈ 10.0387.
2. y (2.0) ≈ 7.6538.
3. y (1.2) ≈ 1.0879.
4. y (1.5) ≈ 0.3416, y (1.6) ≈ 0.5722, y (1.7) ≈ 0.7190.

18

You might also like