51
+ Numerical Integration Techniques A Brief Introduction

Numerical Integration

Embed Size (px)

DESCRIPTION

Power point presenting some numerical integration metjods

Citation preview

Numerical Methods for Differential Equations

Numerical Integration TechniquesA Brief Introduction+ObjectivesStart Writing your OWN ProgramsMake Numerical Integration accurateMake Numerical Integration fastCUDA acceleration

2+2The same Objective

Lord, make me accurate and fast.- Mel Gibson, Patriot3+ Schedule4+PreliminariesBasic CalculusDerivativesTaylor series expansion

Basic Programming SkillsOctave5

+Bad Joke: Exponential function e to x and constant 1 is walking on some street. They find differential operator walking to them. Constant 1 is very nervous, he said I will become 0 if I meet the differential operator. The exponential function said, I am good at this. And he go to say hello to the differential operator. He says, hello, I am the exponential function e to the x. The reply was Hi, and I am df/dy.Stokes TheoremOctave is just a Matlab Lite. Biologists -> analyze data, mathematician -> the only two software: mathematica, matlab5Numerical DifferentiationDefinition of Differentiation

Problem: We do not have an infinitesimal h Solution: Use a small h as an approximation

6+Numerical DifferentiationApproximation Formula

Is it accurate?Forward Difference

7+Numerical DifferentiationTaylor Series expansion uses an infinite sum of terms to represent a function at some point accurately.

which impliesError Analysis

8+Truncation Error

9+ Numerical DifferentiationRoundoff ErrorA computer can not store a real number in its memory accurately.Every number is stored with an inaccuracy proportional to itself.Denoted

Total Error

Usually we consider Truncation Error more.

Error Analysis

10+Numerical DifferentiationBackward DifferenceDefinition

Truncation Error

No Improvement!

11+Numerical DifferentiationDefinition

Truncation Error

More accurate than Forward Difference and Backward DifferenceCentral Difference

12+Numerical DifferentiationCompute the derivative of function

At point x=1.15

Example

13+Differentiation.m compares the errors of these methods

13Use Octave to compare these methodsBlue Error of Forward Difference Green Error of Backward DifferenceRed Error of Central Difference

14+ 14Numerical DifferentiationMulti-dimensionalApply Central Difference for different parameters

High-Order Apply Central Difference several times for the same parameterMulti-dimensional & High-Order

15+Euler MethodThe Initial Value ProblemDifferential EquationsInitial Conditions

ProblemWhat is the value of y at time t?

IVP

16+Euler MethodConsider Forward Difference

Which impliesExplicit Euler Method

17+Euler MethodSplit time t into n slices of equal length t

The Explicit Euler Method FormulaExplicit Euler Method

18+Euler Method

Explicit Euler Method - Algorithm19+Euler MethodUsing Taylor series expansion, we can compute the truncation error at each step

We assume that the total truncation error is the sum of truncation error of each step

This assumption does not always hold.Explicit Euler Method - Error

20+Euler MethodConsider Backward Difference

Which implies

Implicit Euler Method

21+Euler MethodSplit the time into slices of equal length

The above differential equation should be solved to get the value of y(ti+1)Extra computationSometimes worth because implicit method is more accurateImplicit Euler Method

22+Euler MethodTry to solve IVP

What is the value of y when t=0.5?The analytical solution isA Simple Example

23+Ask students to write the explicit Euler method formula23Euler MethodUsing explicit Euler method

We choose different dts to compare the accuracyA Simple Example

24+Euler Methodtexactdt=0.05errordt=0.025errordt=0.0125error0.11.100161.100300.000141.100220.000061.100190.000030.21.201261.201770.000501.201510.000241.201380.000110.31.304181.305250.001071.304700.000521.304440.000250.41.409681.411500.001821.410570.000891.410120.000440.51.518461.521210.002741.519820.001351.519140.00067A Simple ExampleAt some given time t, error is proportional to dt. 25+Euler MethodFor some equations called Stiff Equations, Euler method requires an extremely small dt to make the result accurate

The Explicit Euler Method Formula

The choice of t matters!Instability

26+Euler MethodInstabilityAssume k=5

Analytical Solution is

Try Explicit Euler Method with different dts

27+Euler_instable.m27Choose dt=0.002, s.t.

Works!

28+ Choose dt=0.25, s.t.

Oscillates, but works.

29+

Choose dt=0.5, s.t.

Instability!

30+ Euler MethodFor large dt, explicit Euler Method does not guarantee an accurate resultStiff Equation Explicit Euler Methodtexactdt=0.5errordt=0.25errordt=0.002error0.40.13533516.389056-0.252.8472640.133980.0100170.80.018316-1.582.897225-0.0156251.8530960.0179510.0199331.20.0024792.25906.714785-0.0009771.3939730.0024050.029751.60.000335-3.37510061.73321-0.0000611.1819430.0003220.03946920.0000455.0625111507.98310.0000150.6639030.0000430.0490931+Euler MethodImplicit Euler Method Formula

Which implies

Stiff Equation Implicit Euler Method

32+Choose dt=0.5, Oscillation eliminated!Not elegant, but works.

33+ Euler_instable_implicit.m33The Three-Variable ModelThe Differential EquationsSingle Cell

34+The Three-Variable ModelSimplify the modelSingle Cell

35+The Three-Variable ModelUsing explicit Euler methodSelect simulation time TSelect time slice length dtNumber of time slices is nt=T/dtInitialize arrays vv(0, , nt), v(0, , nt), w(0, , nt) to store the values of V, v, w at each time stepSingle Cell36+Threevariable.m36The Three-Variable ModelAt each time stepCompute p,q from value of vv of last time stepCompute Ifi, Iso, Ifi from values of vv, v, w of previous time stepSingle Cell

37+The Three-Variable ModelAt each time stepUse explicit Euler method formula to compute new vv, v, and wSingle Cell

38+The Three-Variable Model

39+ Heat Diffusion EquationsThe Model

The first equation describes the heat conductionFunction u is temperature distribution functionConstant is called thermal diffusivityThe second equation initial temperature distribution40

+Heat Diffusion EquationLaplace Operator (Laplacian)Definition: Divergence of the gradient of a function

Divergence measures the magnitude of a vector fields source or sink at some point

Gradient is a vector point to the direction of greatest rate of increase, the magnitude of the gradient is the greatest rateLaplace Operator

41+Heat Diffusion EquationMeaning of the Laplace Operator

Meaning of Heat Diffusion OperatorAt some point, the temperature change over time equals the thermal diffusivity times the magnitude of the greatest temperature change over spaceLaplace Operator

42+Heat Diffusion EquationCartesian coordinates

1D space (a cable)

Laplace Operator

43+Heat Diffusion EquationCompute Laplacian Numerically (1d)Similar to Numerical DifferentiationLaplace Operator

44+Heat Diffusion EquationBoundaries (1d), take x=0 for exampleAssume the derivative at a boundary is 0

Laplacian at boundariesLaplace Operator

45+Heat Diffusion EquationExerciseWrite a program in Octave to solve the following heat diffusion equation on 1d space:

46+Heat Diffusion EquationExerciseWrite a program in Octave to solve the following heat diffusion equation on 1d space:

TIPS:Store the values of u in a 2d array, one dimension is the time, the other is the cable(space)Use explicit Euler MethodChoose dt, dx carefully to avoid instabilityYou can use mesh() function to draw the 3d graph

47+Store u in a two-dimensional array

u(i,j) stores value of u at point x=xi, time t=tj.u(i,j) is computed from u(i-1,j-1), u(i,j-1), and u(i+1,j+1).48+ Heat Diffusion EquationExplicit Euler Method Formula

Discrete Form

49+Heat Diffusion EquationStability

dt must be small enough to avoid instability

50+50The ENDThank You!51+