Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

34
Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method

Transcript of Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Page 1: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Scientific Computing

Numerical Solution Of Ordinary Differential Equations

- Euler’s Method

Page 2: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Bungee Jumper – Coupled ODEs

Page 3: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Bungee Jumper – Coupled ODEs

• We want to model the vertical dynamics of a jumper connected to a stationary platform with a bungee cord. F=ma

• Forces: – mg (gravity, g = acceleration due to gravity)– cd v2 (drag force, cd = drag coefficient, v = velocity)

(need to always retard v, so if falling (v>0) need force neg, if rising (v<0) need force pos to reduce dv/dt) (use sign(v) for drag force)– k (x-L) (spring force, x = distance measured down from platform, L = rest length of cord) – γ v (damping force, γ is damping coefficient of cord)

Page 4: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Bungee Jumper – Coupled ODEs

• We get

• Dividing by m we get:

mdv

dtmg sign(v)cdv 2 k(x L) v k = = 0 if

x L

vm

Lxm

kv

m

cvsigng

dt

dv 2d )()( k = = 0 if

x L

Page 5: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Bungee Jumper – Coupled ODEs

• Need to solve two simultaneous ODEs for x and v

vm

Lxm

kv

m

cvsigng

dt

dv

vdt

dx

2d )()(

k = = 0 if x L

Page 6: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Solving First Order ODE’s

• A general form for a first order ODE is

• Or alternatively

• We desire a solution x(t) which satisfies this ODE and one specified boundary condition.

x(a) = c

F t, x,dx

dt

0

dx

dt f t,x

Page 7: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Initial Value Problem

• An Initial Value Problem (IVP) is to solve a differential equation (of some order) subject to one or more initial conditions.

Page 8: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Analytic Solutions

• Suppose

• This can be clearly solved by integration:

dx

dtt 2 x(0) 1

dx t 2dt x t 3

3C

x(0) 1 C 1

x t 3

31

Page 9: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Numerical Solution

• For many ODE’s integration is not possible, need to do a numerical approximation to the solution.

• To find a numerical solution we divide the interval [a,b] for the independent variable t into n subintervals or steps.

Page 10: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Numerical Solution

• Then the value of the true solution is approximated at these n values of t.

• We denote the approximation at these pts by so that

ti t0 ih ni ,...,1,0n

abh

x i

x i x ti

Page 11: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Numerical Solution

• Let x(t) be the actual solution for dx/dt at the step values.

• Then, assuming no roundoff error, the difference in the calculated and true value is the truncation error,

i x i x ti

Page 12: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Numerical Solution

Numerical algorithms for solving 1st order odes for an initial condition are based on one of two approaches:

1. Direct or indirect use of the Taylor series expansion for the solution function

2. Use of open or closed integration formulas.

x t

Page 13: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Numerical Solution

The various solution algorithms are classified into:

• One-step: calculation of xi+1 given the differential equation and previous value: xi

• Multi-step: in addition to the previous information the algorithm requires values of t and x outside of the interval under consideration.

Page 14: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Numerical Solution

• The first method considered is based on the Taylor series expansion.

• It forms the basis for some of the other methods.

Page 15: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Taylor Series

• For this method we express the solution x(t) about some starting point t0 using a Taylor expansion.

• The ODE is given by

x t0 h x t0 hx '(t0) h2

2x ' '(t0)

h3

6x' ' '(t0) ...

dx

dt f t,x

Page 16: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Taylor Series

• Thus, by substitution from

• Where and … etc

x t0 h x t0 hf t0, x t0

h2

2f t0,x t0 h3

6f t0, x t0 ...

dx

dt f t, x

f t, x t denotesd

dtf t, x t

f ' ' t, x t denotesd2

dt 2 f t, x t

Page 17: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Error Analysis for Taylor Approximation

• Suppose we use the nth order Taylor series approximation

to generate the value of x1=x(t1). How close are we to the actual value?

00)(

00

2

00001

,!

,2

,)(

txtfn

htxtf

h

txthftxhtxtx

nn

Page 18: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Error Analysis for Taylor Approximation

• In general, suppose we generate points for x by:

to generate the value of xi+1=x(ti+1). How close are we to the actual value?

iin

n

ii

iiiii

txtfn

htxtf

h

txthftxhtxtx

,!

,2

,)(

)(2

1

Page 19: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Error Analysis for Taylor Approximation

• The exact value for x(ti+1) is given by

x ti1 x ti h x ti hf ti,x ti

h2 f ti,x ti

2!

h3 f ti,x ti 3!

...

hn f n 1 ti,x ti

n!

hn1 f n ,x n 1 !

1, ii xxin

Page 20: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Error Analysis for Taylor Approximation

• Algorithms for which the last term in expansion is dropped are of order hn.

• The error is of order hn+1.• The local truncation error is bounded as

follows• where

et hn1

n 1 ! M

M f n , x max

in ti,ti1

Page 21: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Taylor Series Solution

• Note: differentiation of f(t,x) can be complicated.

• Direct Taylor expansion is not used other than the simplest case,

x ti1 x ti hf ti,x ti O h2

Page 22: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Euler’s Method

x ti1 x ti hf ti,x ti

Page 23: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Euler’s Method

• The problem with the simple Euler method is the inherent inaccuracy in the formula.

Page 24: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Euler’s Method

• The geometric interpretation is shown the diagram.

x(t0)

x1

x(t1)

t0 t1

x(t)

h

t

x

Page 25: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Euler’s Method

• The solution across the interval [t0,t1] is assumed to follow the line tangent to x(t) at t0.

x(t0)

x1

x(t1)

t0 t1

x(t)

h

t

x

Page 26: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Euler’s Method

• When the method is applied repeatedly across several intervals in sequence, the numerical solution traces out a polygon segment with sides of slope fi, i=0,1,2,…,(n-1).

Page 27: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Euler’s Method

• The simple Euler method is a linear approximation, and is a perfect solution only if the function is linear (or at least linear in the interval).

• This is inherently inaccurate.• Because of this inaccuracy small step sizes are

required when using the algorithm.

Page 28: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

http://numericalmethods.eng.usf.edu

Example

A ball at 1200K is allowed to cool down in air at an ambient temperature of 300K. Assuming heat is lost only due to radiation, the differential equation for the temperature of the ball is given by

Kdt

d12000,1081102067.2 8412

Find the temperature at 480t seconds using Euler’s method. Assume a step size of

240h seconds.

Page 29: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Solution

K

f

htf

htf iiii

09.106

2405579.41200

24010811200102067.21200

2401200,01200

,

,

8412

0001

1

Step 1:

1 is the approximate temperature at 240240001 httt

K09.106240 1

8412 1081102067.2

dt

d

8412 1081102067.2, tf

http://numericalmethods.eng.usf.edu

Page 30: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Solution Cont

For 09.106,240,1 11 ti

K

f

htf

32.110

240017595.009.106

240108109.106102067.209.106

24009.106,24009.106

,

8412

1112

Step 2:

2 is the approximate temperature at 48024024012 httt

K32.110480 2

http://numericalmethods.eng.usf.edu

Page 31: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Solution Cont

The exact solution of the ordinary differential equation is given by the solution of a non-linear equation as

9282.21022067.000333.0tan8519.1300

300ln92593.0 31

t

The solution to this nonlinear equation at t=480 seconds is

K57.647)480(

http://numericalmethods.eng.usf.edu

Page 32: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Comparison of Exact and Numerical Solutions

Figure 3. Comparing exact and Euler’s method

0

200

400

600

800

1000

1200

1400

0 100 200 300 400 500

Time, t(sec)

Te

mp

era

ture

,

h=240

Exact Solution

θ(K

)

http://numericalmethods.eng.usf.edu

Page 33: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Step, h (480) Et |єt|%

4802401206030

−987.81110.32546.77614.97632.77

1635.4537.26100.8032.60714.806

252.5482.96415.5665.03522.2864

Effect of step size

Table 1. Temperature at 480 seconds as a function of step size, h

K57.647)480( (exact)

http://numericalmethods.eng.usf.edu

Page 34: Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.

Comparison with exact results

-1500

-1000

-500

0

500

1000

1500

0 100 200 300 400 500

Time, t (sec)Tem

per

atu

re,

Exact solution

h=120h=240

h=480

θ(K

)

Figure 4. Comparison of Euler’s method with exact solution for different step sizes

http://numericalmethods.eng.usf.edu