31
Integration of Ordinary Differential Equations dy/dt = f(t,y) Agus Suryanto Department of Mathematics Faculty of Mathematics and Natural Sciences Brawijaya University E-mail: [email protected]

ODE-Euler_1

Embed Size (px)

DESCRIPTION

EULER METHODS

Citation preview

Page 1: ODE-Euler_1

Integration of OrdinaryDifferential Equations

dy/dt = f(t,y)

Integration of OrdinaryDifferential Equations

dy/dt = f(t,y)

Agus SuryantoDepartment of Mathematics

Faculty of Mathematics and Natural Sciences

Brawijaya University

E-mail: [email protected]

Agus SuryantoDepartment of Mathematics

Faculty of Mathematics and Natural Sciences

Brawijaya University

E-mail: [email protected]

Page 2: ODE-Euler_1

Definition of the problem:Integration of a system of ordinary differential equations (ODEs) in the explicit form:

with the following initial conditions:

Definition of the problem:Integration of a system of ordinary differential equations (ODEs) in the explicit form:

with the following initial conditions:

Definition of the Problem

( ) ( ) ,d

t t f tdt

y y y

0 0( )t y y

Page 3: ODE-Euler_1

Order of the ODE:A system of ODEs of order m is defined as:

with the following initial conditions:

This system can be transformed into a system of ODEs of first order by introducing as new variables:

Order of the ODE:A system of ODEs of order m is defined as:

with the following initial conditions:

This system can be transformed into a system of ODEs of first order by introducing as new variables:

Higher Order ODEs

( ) ( 1), , ', ,m mf t y y y y

0 0( )t y y 0 0'( ) 't y y ( 1) ( 1)

0 0( )m mt y y…

1y y

2'y y ( 1)m

m

y y…

2

( 0) 2

2 ( ) ( 0) 0

( 0) 1

y t

y y y y t with y t

y t

1 1 2

2 2 32

3 3 3 2 12 ( )

y y y y

y y y y

y y y y y y t

10

00

20

3

2

1

y

y

y

Page 4: ODE-Euler_1

Autonomous Systems

Definition:

A system is autonomous when the independent variable t does not explicitly appear in the system.

Definition:

A system is autonomous when the independent variable t does not explicitly appear in the system.

( )t f y y

It is always possible to transform a non-autonomous system of ODEs into an autonoumous one

( ) ,y t f t y 1 1 1 2

2 2

( , )

1

y y y f y y

y t y

Page 5: ODE-Euler_1

Example: One ODE

( ) 2

(0) 1

y t y t

y

( ) ( )

'( ) ( ) ( ) ( )

( ) ( )p s ds p s ds

y t r t p t y t

y t e k r t e dt

Johann Bernoulli (Basel, July 27, 1667 - January 1, 1748)

21( ) 3 2 1

4ty t e t

0 0.2 0.4 0.6 0.8 11

2

3

4

5

6

7

t

y

Numerical solution?

Page 6: ODE-Euler_1

Example: One ODE

( ) 2

(0) 1

y t y t

y

21( ) 3 2 1

4ty t e t

0 0.2 0.4 0.6 0.8 11

2

3

4

5

6

7

t

y

Let us use the Taylor expansion of y(t):

2

1 1 1

2 2( , )

n n n n n nn

n n n n n

dyy y t t o t t

dt

y y h o h y h f t y o h

1 ( , )n n n ny y hf t y

0 0.2 0.4 0.6 0.8 11

2

3

4

5

6

7

t

y1

0.2

1.4

h

y

00 0

0

1( , ) 2

0

yf t y

t

Leonhard Euler (Basel, April 15, 1707 – September 18, 1783)

• y = f(x)

• ( ) 0ut

Page 7: ODE-Euler_1

Example: One ODE

( ) 2

(0) 1

y t y t

y

21( ) 3 2 1

4ty t e t

1 ( , )n n n ny y hf t y

0 0.2 0.4 0.6 0.8 11

2

3

4

5

6

7

t

y

In the next slides, the following notation will be used:y(tn) = exact values of the variables y in tn

yn = approximate values of the variables y in tn

y’(tn) = exact values of the derivatives y’ in tn

y’n = approximate values of the derivatives y’ in tn

h = integration step

Page 8: ODE-Euler_1

Few More Definitions…

One step integration algorithms:

Multi-step integration algorithms:

Explicit integration algorithms:

Implicit integration algorithms:

One step integration algorithms:

Multi-step integration algorithms:

Explicit integration algorithms:

Implicit integration algorithms:

1,nn n n

h t y y f y

1 12 ,nn n n

h t y y f y

1

2 1

1 21

,

,

/ 2

n n

n n

n n

h t

h t h

k f y

k f y k

y y k k

11 1,nn n n

h t y y f y

Page 9: ODE-Euler_1

Accuracy of Integration Algorithms

Local error: it is always a known power of h.

Order of the algorithm: an algorithm has an order p if it is able to correctly integrate a polynomial of order p.

Convergence: an algorithm is convergent if, for h → 0, the global error (accuracy) decreases (under the hypothesis of no rounding errors)

Local error: it is always a known power of h.

Order of the algorithm: an algorithm has an order p if it is able to correctly integrate a polynomial of order p.

Convergence: an algorithm is convergent if, for h → 0, the global error (accuracy) decreases (under the hypothesis of no rounding errors)

1,nn n n

h t y y f y 2

2ny

h

An algorithm of order p has always a local error in the order of o(hp+1)

2''

2h

yn

Page 10: ODE-Euler_1

Examples

1,nn n n

h t y y f y

Forward Euler

0 0.2 0.4 0.6 0.8 11

2

3

4

5

6

7

t

y

h = 0.01h = 0.1h = 0.2

Error at t = 1 (h = 0.01)• Euler:1.72%

Page 11: ODE-Euler_1

Conditioning of the Problem

Definition: a system of ODEs is well conditioned if small error in the function (e.g. parameters) and/or in the initial conditions generate a small error in the solution (without rounding errors!)

Perturbations:

Definition: a system of ODEs is well conditioned if small error in the function (e.g. parameters) and/or in the initial conditions generate a small error in the solution (without rounding errors!)

Perturbations:

Conditioning has nothing to do with the stability of the algorithm

0 0

' , ( )

( ) ( )

t t

t t

y f y

y y

Page 12: ODE-Euler_1

Example of Bad Conditioning

Consider the following ODE:

The general solution is:

If the initial condition is actually y(0) = 1, then:

If the initial condition is instead y(0) = 1.0001, then:

Consider the following ODE:

The general solution is:

If the initial condition is actually y(0) = 1, then:

If the initial condition is instead y(0) = 1.0001, then:

' 9 10

(0) 1

ty y e

y

9( ) t ty t ce e

( ) ty t e

9( ) 0.0001 t ty t e e 0 0.5 1 1.5 2

10-2

100

102

104

t

y

y(0) = 1.0001y(0) = 1

Page 13: ODE-Euler_1

Example of Bad Conditioning

Consider the following ODEs:

They are all characterized by the same solution:

Let’s perturb the initial condition (y(0) = 1.0001):

Consider the following ODEs:

They are all characterized by the same solution:

Let’s perturb the initial condition (y(0) = 1.0001):

' 9 10 (0) 1

' (0) 1

' (0) 1

t

t

y y e y

y e y

y y y

( ) ty t e

9( ) 0.0001

( ) 0.0001

( ) 0.0001

t t

t

t t

y t e e

y t e

y t e e

diverging error

constant error

converging error

If all the eigenvalues of the Jacobian of a system of ODEs

have a positive real part, the system is ill conditioned.

with

' ,ty f y

Re( ( )) 0λ J iik

j

fJ

y

Page 14: ODE-Euler_1

Stability of the Algorithms

Local errorExample: the Forward Euler Method:

The Taylor expansion of y(t):

Subtracting the two expressions gives result:

If we know exactly y in tn:

Local errorExample: the Forward Euler Method:

The Taylor expansion of y(t):

Subtracting the two expressions gives result:

If we know exactly y in tn:

1 ,n n n ny y h f t y

21

2

( ) ( ) ( ) 0.5 ( )

( ) , ( ) 0.5 ( )

n n n n

n n n n

y t y t hy t h y

y t h f t y t h y

21 1( ) ( ) , ( ) , 0.5n n n n n n n ny t y y t y h f t y t f t y h y

21 0.5 ( )L

n nh y

Page 15: ODE-Euler_1

Stability of the Algorithms

Propagation error (always applied to the Forward Euler method)

We don't know exactly the value of y in tn

→ we don't compute the correct value of f(t,y).

Let us apply the mean value theorem to the function f(t,y)

Let us substitute this expression into

Propagation error (always applied to the Forward Euler method)

We don't know exactly the value of y in tn

→ we don't compute the correct value of f(t,y).

Let us apply the mean value theorem to the function f(t,y)

Let us substitute this expression into

( , ( )) ( , )( , )

( )n n n n

n yn n

f t y t f t y df t f

y t y dy

1 1( ) ( ) , ( ) , Ln n n n n n n n ny t y y t y h f t y t f t y

1 1G G Ln y n nh f

Mean value theorem: given a function f(x) and its values at two extremes xa and xb, it exists a point inside the interval [xa, xb] such that:

( ) ( )( )b a

b a

x x

x x

f f f

Page 16: ODE-Euler_1

Local and Global Error

Local error is the amount by which the numerical and exact solutions differs after one step assuming that both were exact at and prior to the beginning of the step

Page 17: ODE-Euler_1

Stability of the Algorithms

Consequences:

1. if fy > 0 (the ODE is bad conditioned) |k| > 1 for h > 0

2. if fy < 0 (the ODE is well conditioned) |k| < 1 for

Consequences:

1. if fy > 0 (the ODE is bad conditioned) |k| > 1 for h > 0

2. if fy < 0 (the ODE is well conditioned) |k| < 1 for

The Forward Euler method is stable only if:

where k is the amplification factor

1 1yhfk

2

y

hf

Page 18: ODE-Euler_1

Example - 1

Let’s consider ODE: 00; yyydt

dy

The Euler method of this ODE: nn yhy 11

The method is stable if 11 k h

hIm

hRe-1

-1

1

-2

Page 19: ODE-Euler_1

Example - 2

.. Let’s consider ODE: 100;10; yydt

dy

h = 0.001

n tn yn y(n) en

0 0.000 1.00000 1.00000 0.000001 0.001 0.90000 0.90484 0.004842 0.002 0.81000 0.81873 0.008733 0.003 0.72900 0.74082 0.011824 0.004 0.65610 0.67032 0.014225 0.005 0.59049 0.60653 0.016046 0.006 0.53144 0.54881 0.017377 0.007 0.47830 0.49659 0.018298 0.008 0.43047 0.44933 0.018869 0.009 0.38742 0.40657 0.01915

10 0.010 0.34868 0.36788 0.01920

h yn en en / y(n)1E-03 2.6561E-5 1.888E-5 4.1495E-11E-04 4.3171E-5 2.229E-6 4.9090E-21E-05 4.5173E-5 2.266E-7 4.9908E-3

Solution and error at t = 0.1

Local error

en is decreasing linearly with h

Page 20: ODE-Euler_1

Example - 3

Let us integrate the following ODE:

The ODE is well conditioned (fy = -10) and its analytical solution is (y(0) = 1):

For t → ∞, it can be observed that y(t) → 0.

Let us know use the forward Euler method to solve numerically the ODE:

yn → 0 only if:

Let us integrate the following ODE:

The ODE is well conditioned (fy = -10) and its analytical solution is (y(0) = 1):

For t → ∞, it can be observed that y(t) → 0.

Let us know use the forward Euler method to solve numerically the ODE:

yn → 0 only if:

( ) 10y t y

10( ) ty t e

1 ( , ) 1 10n n n n ny y hf t y h y

01 10n

ny h y

1 10 1h 2

0.210

h

or:

Page 21: ODE-Euler_1

Example 3 - Continued

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

t

y

Exact Solution

Euler Solution; h = 0.01

0 0.5 1 1.5 2 2.5 3 3.5 4-600

-400

-200

0

200

400

600

800

t

y

Exact solution

Euler solution; h = 0.25

Page 22: ODE-Euler_1

Stability and Precision

When dealing with systems of ODEs, in order to evaluate the stability of the integration method, we must consider the Jacobian of the system (instead of fy).

It is common practice to reduce the problem of stability to the study of the stability of the ODE:

where l is the largest eigenvalue of the Jacobian. Note that the eigenvalues are typically complex.

For instance, for the forward Euler method:

• the method is stable if:

• the local error of the method is:

When dealing with systems of ODEs, in order to evaluate the stability of the integration method, we must consider the Jacobian of the system (instead of fy).

It is common practice to reduce the problem of stability to the study of the stability of the ODE:

where l is the largest eigenvalue of the Jacobian. Note that the eigenvalues are typically complex.

For instance, for the forward Euler method:

• the method is stable if:

• the local error of the method is:

( ) ( )y t y t

22 e

2 2

tL y

h h

1 1yhfk Let us introduce the maximum step in the local error (l < 0):

max max

22eL th

Page 23: ODE-Euler_1

Stiff Systems• Consider IVP:

which has the solution: where a is a large positive number

• Consider IVP:

which has the solution: where a is a large positive number

02 0;0;2 yyttty

dt

dy

20 exp ttyty

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.2

0.4

0.6

0.8

1

1.2

1.4

t

y

inner solutionouter/reduced solutionsolution of the ODE

10 A stiff system is the one involving rapidly changing components together with slowly changing ones. Stiff ODEs have both fast and slow components

Page 24: ODE-Euler_1

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-0.5

0

0.5

1

1.5

2

2.5

3

3.5x 10

9

t

yEuler; h = 0.1Exact

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

t

y

exactEuler; h = 0.001Euler; h = 0.01

Stiff Systems: Euler solution

A problem is stiff in an interval if the step size needed for absolute stability is much smaller than the step size required for accuracy

Page 25: ODE-Euler_1

Backward (Implicit) Euler

21111 ))((

2

1))(()()( nnnn ttcytttytyty

2111 )(

2

1))(,()()( hcytythftyty nnnn

Write down a Taylor expansion for y about tn+1

Evaluate at tn and note y’=f

Drop h2 term to get Euler’s method (backward Euler)

),(),( 111111 nnnnnnnn ythfyyythfyy

Page 26: ODE-Euler_1

Stability Implicit Euler Method.

.

Let’s consider ODE: 00; yyydt

dy

The Implicit Euler method of this ODE: 1

111 ,

nn

nnnn

yhy

ythfyy

h

yy n

n 11

Solution:

1111

1

hor

hStability condition:

Page 27: ODE-Euler_1

Implicit Euler Method: Stability Region

11 h

Page 28: ODE-Euler_1

Backward Euler Forward Euler

Explicit vs. Implicit Methods

),(1 nnnn ythfyy ),( 111 nnnn wthfyy

• Forward Euler is an explicit method. Computing the new approximation yn+1 is simple.

restricted by stability region• Backward Euler is an implicit method. Computing

the new approximation yn+1 can be more complicated; it appears on both sides of the equation and inside the f function.

Larger stability region

Page 29: ODE-Euler_1

Newton Method

Page 30: ODE-Euler_1
Page 31: ODE-Euler_1