Numerical Solutions to ODEs Nancy Griffeth January 14

  • Slides: 20
Download presentation
Numerical Solutions to ODEs Nancy Griffeth January 14, 2014 Funding for this workshop was

Numerical Solutions to ODEs Nancy Griffeth January 14, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex Systems, ” an NSF Expedition in Computing (Award Number 0926200).

ODE Numerical Differentiation n Definition of Differentiation Problem: We do not have an infinitesimal

ODE Numerical Differentiation n Definition of Differentiation Problem: We do not have an infinitesimal h Solution: Use a small h as an approximation 2

ODE Forward Difference & Backward Difference n Forward Difference n Backward Difference 3

ODE Forward Difference & Backward Difference n Forward Difference n Backward Difference 3

ODE Numerical Differentiation - Example n Compute the derivative of function n At point

ODE Numerical Differentiation - Example n Compute the derivative of function n At point x=1. 15 4

Euler Method Explicit Euler Method n Consider Forward Difference n Which implies 5

Euler Method Explicit Euler Method n Consider Forward Difference n Which implies 5

Euler Method Explicit Euler Method n Split time t into n slices of equal

Euler Method Explicit Euler Method n Split time t into n slices of equal length Δt n The Explicit Euler Method Formula 6

Euler Method Explicit Euler Method - Algorithm 7

Euler Method Explicit Euler Method - Algorithm 7

Euler Method Implicit Euler Method n Consider Backward Difference n Which implies 8

Euler Method Implicit Euler Method n Consider Backward Difference n Which implies 8

Euler Method Implicit Euler Method n n Split the time into slices of equal

Euler Method Implicit Euler Method n n Split the time into slices of equal length The above differential equation should be solved to get the value of y(ti+1) n n Extra computation Sometimes worth because implicit method is more accurate 9

Euler Method A Simple Example n n n Try to solve IVP What is

Euler Method A Simple Example n n n Try to solve IVP What is the value of y when t=0. 5? The analytical solution is 10

Euler Method A Simple Example n Using explicit Euler method n We choose different

Euler Method A Simple Example n Using explicit Euler method n We choose different dts to compare the accuracy 11

Euler Method A Simple Example t exact dt=0. 05 error dt=0. 025 error dt=0.

Euler Method A Simple Example t exact dt=0. 05 error dt=0. 025 error dt=0. 012 5 error 0. 1 0. 2 0. 3 0. 4 0. 5 1. 10016 1. 20126 1. 30418 1. 40968 1. 51846 1. 10030 1. 20177 1. 30525 1. 41150 1. 52121 0. 00014 0. 00050 0. 00107 0. 00182 0. 00274 1. 10022 1. 20151 1. 30470 1. 41057 1. 51982 0. 00006 0. 00024 0. 00052 0. 00089 0. 00135 1. 10019 1. 20138 1. 30444 1. 41012 1. 51914 0. 00003 0. 00011 0. 00025 0. 00044 0. 00067 At some given time t, error is proportional to dt. 12

Euler Method A Simple Example n For some equations called Stiff Equations, Euler method

Euler Method A Simple Example n For some equations called Stiff Equations, Euler method requires an extremely small dt to make result accuracy The Explicit Euler Method Formula n The choice of Δt matters! n 13

Euler Method A Simple Example n Assume k=5 n Analytical Solution is n Try

Euler Method A Simple Example n Assume k=5 n Analytical Solution is n Try Explicit Euler Method with different dts 14

Choose dt=0. 002, s. t. Works! 15

Choose dt=0. 002, s. t. Works! 15

Choose dt=0. 25, s. t. Oscillates, but works. 16

Choose dt=0. 25, s. t. Oscillates, but works. 16

Choose dt=0. 5, s. t. Instability! 17

Choose dt=0. 5, s. t. Instability! 17

Euler Method Stiff Equation – Explicit Euler Method n For large dt, explicit Euler

Euler Method Stiff Equation – Explicit Euler Method n For large dt, explicit Euler Method does not guarantee an accurate result t exact dt=0. 5 error dt=0. 25 error dt=0. 002 error 0. 4 0. 135335 1 6. 389056 -0. 25 2. 847264 0. 13398 0. 010017 0. 8 0. 018316 -1. 5 82. 897225 -0. 015625 1. 853096 0. 017951 0. 019933 1. 2 0. 002479 2. 25 0. 002405 0. 02975 1. 6 0. 000335 -3. 375 0. 000322 0. 039469 2 0. 000045 5. 0625 906. 714785 -0. 000977 1. 393973 10061. 733 21 -0. 000061 1. 181943 111507. 98 31 0. 000015 0. 663903 0. 000043 0. 04909 18

Euler Method Stiff Equation – Implicit Euler Method n Implicit Euler Method Formula n

Euler Method Stiff Equation – Implicit Euler Method n Implicit Euler Method Formula n Which implies 19

Choose dt=0. 5, Oscillation eliminated! Not elegant, but works. 20

Choose dt=0. 5, Oscillation eliminated! Not elegant, but works. 20