48
© Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed Amen Paul Bilokon Adam Brinley Codd Minal Fofaria Tejas Shah

© Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

Embed Size (px)

Citation preview

Page 1: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Numerical Solution ofDifferential Equations

3rd year JMC group project ● Summer Term 2004

Supervisor: Prof. Jeff Cash

Saeed Amen

Paul Bilokon

Adam Brinley Codd

Minal Fofaria

Tejas Shah

Page 2: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Agenda

Adam: Differential equations and numerical methods

Paul: Basic methods (FE, BE, TR). Problem: “circle”

Saeed: Advanced methods (4th order). Problem: Kepler’s equation

Minal: Stiff equations Tejas: Derivation of 6th order method

Page 3: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Agenda

Adam: Differential equations and numerical methods

Paul: Basic methods (FE, BE, TR). Problem: “circle”

Saeed: Advanced methods (4th order). Problem: Kepler’s equation

Minal: Stiff equations Tejas: Derivation of 6th order method

Page 4: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Introduction to Differential Equations

Equations involving a function y of x, and its derivatives

Model real world systems General Equation:

Page 5: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Introduction to Differential Equations

Simple example

Solution obtained by integrating both sides

Initial values can determine c

Page 6: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Introduction to Differential Equations

Special case when equations do not involve x E.g.

Initial values y(0) = 1 and y'(0) = 0, solution is

Page 7: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Introduction to Differential Equations

Kepler’s Equations of Planetary Motion

Difficult to solve analytically – we use numerical methods instead

Page 8: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Introduction to Differential Equations

Forward Euler and Backward Euler Trapezium Rule

General method– Use initial value of y at x=0– Calculate next value (x=h for small h) using gradient– Call this y1 and repeat

Need formula for yn+1 in terms of yn

Page 9: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Agenda

Adam: Differential equations and numerical methods

Paul: Basic methods (FE, BE, TR). Problem: “circle”

Saeed: Advanced methods (4th order). Problem: Kepler’s equation

Minal: Stiff equations Tejas: Derivation of 6th order method

Page 10: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Agenda

Adam: Differential equations and numerical methods

Paul: Basic methods (FE, BE, TR). Problem: “circle”

Saeed: Advanced methods (4th order). Problem: Kepler’s equation

Minal: Stiff equations Tejas: Derivation of 6th order method

Page 11: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Euler’s Methods

Simplest way of solving ODEs numerically

Does not always produce reasonable solutions

Forward Euler (explicit) and Backward Euler (implicit)

Page 12: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Forward Euler

y(x + h) = y(x) + h y’(x)

Explicit Eloc = ½h2y(2)() h2

First order Asymmetric

x0 x1 x2

x

y

y0

y1

y2

h h

(x0, y0)

(x1, y1)

(x2, y2)

True solution

Approximated solution

Slope f(x1, y1)

Slope f(x0, y0)

Page 13: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Backward Euler

y(x + h) = y(x) + h y’(x + h)

Implicit Eloc = - ½h2y(2)() h2

First order Asymmetric

x0 x1 x2

x

y

y0

y1

y2

h h

(x0, y0)

(x1, y1)

(x2, y2)

True solution

Approximated solution

Slope f(x2, y2)

Slope f(x1, y1)

Page 14: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Trapezium Rule

Average of FE and BE Implicit Eloc = - (h3/12) f(2)()

h3

Second order Symmetric

y(x + h) = y(x) + ½ h [y’(x) + y’(x + h)]

Page 15: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Example Problem: “Circle”

Consider y’’ = -y, with initial conditions– y(0) = 1– y’(0) = 0

The analytical solution is y = cos x, that can be used for comparison with numerical solutions

Page 16: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Plots for the True Solution

Time series plot (xy) Phase plane plot (zy)

Page 17: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Time Series

y

x

Page 18: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Phase Plane Plots: FE & BE

Forward Euler Backward Euler

Page 19: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Phase Plane Plots: TR

FE & BE fail: non-periodic TR: OK, periodic soln

W h y ?

Page 20: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Symmetricity

TR is symmetric, whereas FE & BE are not

y(x + h) = y(x) + ½ h [y’(x) + y’(x + h)]

h -hy(x - h) = y(x) - ½ h [y’(x) + y’(x - h)]

X := x - hy(X + h) = y(X) + ½ h [y’(X) + y’(X +

h)]

Still

TR!

Page 21: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Symmetricity

TR is symmetric, whereas FE & BE are not

y(x + h) = y(x) + h y’(x)h -h

y(x - h) = y(x) - h y’(x)X := x - h

y(X + h) = y(X) + h y’(X + h)

Still

FE?

Page 22: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Time Step

h = 10 -1

h = 10 -2

Page 23: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Agenda

Adam: Differential equations and numerical methods

Paul: Basic methods (FE, BE, TR). Problem: “circle”

Saeed: Advanced methods (4th order). Problem: Kepler’s equation

Minal: Stiff equations Tejas: Derivation of 6th order method

Page 24: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Agenda

Adam: Differential equations and numerical methods

Paul: Basic methods (FE, BE, TR). Problem: “circle”

Saeed: Advanced methods (4th order). Problem: Kepler’s equation

Minal: Stiff equations Tejas: Derivation of 6th order method

Page 25: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

After Euler and TR

Can create higher order methods, which have far smaller global errors

Methods are more complex and require more computation on each step

But for same step size more accurate Introduce concept of half step

Page 26: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Two Fourth Order Methods

yn+1 – yn = yn + h/2(y’n) + (h2/12)(4y’’n+½+ 2y’’n)

y’n+1 – y’n = h/6(y’’n+1 + 4y’’n+½+ y’’n) (*)

Then to calculate the half-step we use either A or B– A) yn+ ½ = ½(yn+1 + yn) – h2/48(y’’n+1 + 4y’’ n+½

+ y’’n)

– B) yn+ ½ = yn + ½y’n – h2/192(-2y’’n+1 + 12y’’ n+½ + 14y’’n)

Which one is more accurate? (next slide) Solve iteratively and then apply solution to find derivative

(*)

Page 27: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Creating Method A

Start with– yn+1 – yn = h/6[y’n+1

+ 4y’n+½ + y’n] (1)

– diff. y’n+1 – y’n = h/6[y’’n+1 + 4y’’n+½ + y’’n] (2)

– yn+½= ½(yn+1 + y’n) – h/8(y’n+1 – y’n) (3)

– diff. y’n+½= ½(y’n+1 + y’’n) – h/8(y’’n+1 – y’’n) (4)

subs (4) into (1) (to eliminate y’n+½ ) and eliminate y’n+1 using (2),

then use (2) in (3) to get half-step

Page 28: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Comparing Fourth Order Methods

Comparing errors when solving circle problem

Both A and B produce a much smaller order of error than Euler’s

Page 29: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Finding Earth’s Orbit Around Sun

Kepler’s Equation Can use it to find the orbit of planets Use to find orbit of earth around the sun Work in two dimensions z and y z’’ = -(GM z) / (y2 + z2)3/2

y’’ = -(GM y) / (y2 + z2)3/2

Constants and initial conditions in report

Page 30: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Results Plot

Solution uses small step size h = 0.01

Becomes difficult to tell difference between methods visually

Using h = 0.1 difference is more marked

Page 31: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Agenda

Adam: Differential equations and numerical methods

Paul: Basic methods (FE, BE, TR). Problem: “circle”

Saeed: Advanced methods (4th order). Problem: Kepler’s equation

Minal: Stiff equations Tejas: Derivation of 6th order method

Page 32: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Agenda

Adam: Differential equations and numerical methods

Paul: Basic methods (FE, BE, TR). Problem: “circle”

Saeed: Advanced methods (4th order). Problem: Kepler’s equation

Minal: Stiff equations Tejas: Derivation of 6th order method

Page 33: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Stiff Equations

Certain systems of ODEs are classified as stiff A system of ODEs is stiff if there are two or

more very different scales of the independent variable on which the dependent variables are changing

Some of the methods used to find numerical solutions fail to obtain the required solution

Page 34: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Example

Consider the equation:

With initial conditions:

There are two solutions to this problem

0)1(2

2

ydx

dy

dx

yd

1)0( y

1)0(' y

Page 35: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Example continued

Analytical solution: y=e-x

Unwanted solution: y=e-λx

We will now show how forward Euler is not stable when solving this problem under certain circumstances

Page 36: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Example continued

Let λ = 103 and let (the step size) h = 0.1

Page 37: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Increasing the range of the x-axis

Page 38: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

When h = 0.001

Page 39: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Agenda

Adam: Differential equations and numerical methods

Paul: Basic methods (FE, BE, TR). Problem: “circle”

Saeed: Advanced methods (4th order). Problem: Kepler’s equation

Minal: Stiff equations Tejas: Derivation of 6th order method

Page 40: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Agenda

Adam: Differential equations and numerical methods

Paul: Basic methods (FE, BE, TR). Problem: “circle”

Saeed: Advanced methods (4th order). Problem: Kepler’s equation

Minal: Stiff equations Tejas: Derivation of 6th order method

Page 41: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

A Sixth Order Numerical Method

Has an error term with smallest h degree as h7

Idea is to find values for α, A, B, C, D, E, F, C, D, E, F such that:

Page 42: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Derivation

Compare Taylor’s Expansion of LHS and RHS So for:

– First expand the LHS

Page 43: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Derivation

• Now expand individual terms on RHS of our expression:

• This gives:

Page 44: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Derivation

Equate both sides and solve for constants:

Similarly we can find C, D, E, F and C, D, E, F

Page 45: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Applying 6th Order Method

How to obtain results using derived method.

Produce a set of simultaneous equations and solve. Find y’n+1 from old values and those just obtained. Set x, yn , y’n etc. to new values. Repeat above procedure with updated variables.

Page 46: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Circle Problem Example

Circle is produced for phase plane plot

Page 47: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

© Imperial College London

Kepler’s Equations

• Solution obtained from z-y plot reinforces fourth order method results.

Page 48: © Imperial College London Numerical Solution of Differential Equations 3 rd year JMC group project ● Summer Term 2004 Supervisor: Prof. Jeff Cash Saeed

The End

But perhaps you want more? Read our report Visit our website:

http://www.doc.ic.ac.uk/~pb401/DE