total recall math, part 2 ordinary diff. equations first order ode, one boundary/initial condition:...

24
Lecture 2: Total Recall Math, Part 2

Post on 19-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Lecture 2:

Total RecallMath, Part 2

Page 2: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Ordinary diff. equationsFirst order ODE, one boundary/initial

condition:

Second order ODE

00 )(),,( yxyyxfdx

dy

2

2( , ) ( , )

d y dyf x y g x y

dxdx

Page 3: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

ODEs contn’d2nd order ODE can be replaced with a

system of 1st order ODEs:

Typical situation in RT involves two-point boundary conditions

… or initial condition

),( uxhdx

ddx

du

v

g(x)v

1100 )(,)( yxyyxy

'0

0

00 ,)( yxdx

dyyxy

Page 4: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Runge-KuttaFor the 1st order ODE the Euler method

gives:

this also happens to be first order RK scheme

4th order RK:

Note that RK is directly applicable to a system of ODE and therefore to any order ODE with initial conditions

y y x x f x yi i i i i i 1 1( ) ( , )

)(6336

) ,()5.0 ,5.0()5.0 ,5.0(

),(

543211

34

23

12

1

hOkkkk

yy

kyhxfhkkyhxfhkkyhxfhk

yxfhk

ii

ii

ii

ii

ii

Page 5: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Finite-differencesFor the 1st order ODE:

For the 2nd order ODE:

dy

dxf x y

y y x x fx x y y

k k k kk k k k

( , )

( ) ( , )1 11 1

2 2

d y

dxf x y

y yx x

y yx x

x x x xf x y

k k

k k

k k

k k

k k k kk k

2

2

1

1

1

1

1 1

2 2

( , )

( , )

Page 6: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

2nd order scheme

For k =1 and k =N equations are given by boundary conditions.

1 1 2, 1 for k k k k k k k k NA y B y C y D

Home work 2a:

Derive the value for coefficients in the numerical scheme above

2

2( ) ( )

d y dyf x g x y

dxdx

This particular form of the 2nd order ODE can be approximated by the

following simple FD scheme:

Page 7: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

This numerical scheme results in 3-diagonal matrix:

Solving a system of ODEs leads to a block-diagonal SLE!

Page 8: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

RK versus Finite-diff.RK typically has homogeneous convergence, allows higher orders, has good round-off stability (because errors are controlled on every step).High accuracy my be very expensive, specially in multidimensions (fast increase of the number of steps).FD converges (if it does) much faster. More complex schemes (2nd order and higher) gain stability and convergence speed.Expensive and difficult to check maximum error.

Cook-book: to study solution locally when you have time use RK. When high accuracy must be combined with high performance use FD.

Page 9: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Partial Differential Equations

PDEs come in three flavors: hyperbolic, parabolic, and elliptic

A typical example of a hyperbolic equation is a wave equation:

where v is the velocity of wave propagation

2

22

2

2

x

u

t

u

v

Page 10: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

PDEs examplesAn example of parabolic equation is the diffusion equation:

where D(>0) is the diffusion coefficient

x

u

xt

uD

Page 11: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

PDEs examplesPoisson equation is an example of elliptic type:

where ρ is the source function (density of charges). If ρ is zero for the whole domain we get a special case of Laplace equation

),(2

2

2

2

yxy

u

x

u

Page 12: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Numerical schemesNumerically, the first two types are initial value problems (Cauchy problems):

Initial values

Bou

ndar

y co

nditi

ons

Boundary conditions

Page 13: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Numerical schemesAn elliptic equation is a boundary condition problem:

Boundary conditions

Page 14: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Numerical scheme forPoisson equation

Assuming an equispaced rectangular grid in 2D with stepsize Δ:

In matrix form the scheme looks like this:

which is a 5-diagonal SLE

jijijijijijiji uuuuuu

,2

1,,1,

2

,1,,1 22

kkkkNkNk uuuuuxx

211)1(1 4

Page 15: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Boundaries andgeneralizationThe scheme on the previous slide only

holds inside the domain. The points for

i = 1, Nx and j = 1, Ny are described by the

boundary conditions leading to a system of linear equation Au = b.

In our case, elements on each diagonal of A are constant. In general case, matrix elements along diagonals change.

In 3D more diagonals are present.

Page 16: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Convergence and stabilityApproximation – the accuracy of

approximation of the analytical equation(s) by numerical scheme.

Convergence - the property of the numerical scheme to get closer to the exact solution when the grid becomes denser in some regular way.

Stability - the stability of numerical scheme characterizes the way errors (e.g. finite difference approximation of derivatives) are accumulated during the integration. Stability of the computer implementation of numerical scheme are the way round-off errors are accumulated.

Page 17: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Computational errorsFloating point numbers are stored in 32- or

64-bit long words (IEEE): 01101000011011011110111001000011

11000000110100001011101001000100010111110111100...

Multiplications/divisions do not loose much precision but subtraction/addition is a danger

sign

sign

expo

nent

expo

nent

man

tiss

a

man

tiss

a

Page 18: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

HOME WORK 2b: convergence Numerical differentiating:

Is there an optimal ?

1 1

1 1

; ?limi 1 i

i i i i

x xi i i i

y y y ydy

dx x x x x

Page 19: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Diffusion equationInitial value problem:

can be approximated as:

11 1

2

1 1 11 1

2

2

2

j j j j ji i i i i

j j ji i i

u u u u uD

t x

u u u

x

2

2

u uD

t x

i-1 i i+1 i-1 i i+1

Space

j T

ime

j+1 Explicit Implicit

Page 20: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Stability analysis of numerical schemesWe represent the approximation errors our

solution ulm with Fourier components:

Substituting individual components to the finite difference scheme we find the condition that results in corresponding to the unlimited error growth. For the diffusion equation this condition is: Courant condition

m m m am t ikl xl l l m k

k

u u u e v e

2

D tC

x

1 1m ml lu u

Page 21: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Explicit or implicit?New sense of stability: how dramatic will

be the solution after many time steps if we change the initial conditions a little bit?

Explicit schemes (α=1, β=0) tend to have better convergence

Purely implicit schemes (α=0, β=1) tend to be more stable

Combining the two (α>0, β>0) helps to get the optimal scheme

Page 22: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Integration: Gauss quadraturesFor any “reasonable” function f(x) the

integral with kernel K(x) can be approximated as a sum of function values

in nodes xi multiplied by weights.

If f(x) can be represented with orthogonal polynomials exactly, the quadrature formula is also exact.

)()()(N

1i

a

b ii xfdxxfxK

Page 23: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Non-linear equationsFor system of non-linear equations weoften use Newton-Raphson scheme:

Page 24: Total Recall Math, Part 2 Ordinary diff. equations First order ODE, one boundary/initial condition: Second order ODE

Home work 2:c. Write a simple program for 4x4

matrix inversion with Gauss-Jordan elimination and partial pivoting. Test round-off stability by doing many inversions of a random 4 by 4 matrix.

d. Propose the scheme (flow chart) for solving SLE with 4x4 block-diagonal matrix

e. Write (or use NR routine) 4th order RK and FD scheme for the equation:2

32

; (0) 1; (15) 10d y xy e y ydx