Download presentation
Presentation is loading. Please wait.
Published byGeraldine Underwood Modified over 9 years ago
1
Fin500J Topic 7Fall 2010 Olin Business School 1 Fin500J Mathematical Foundations in Finance Topic 7: Numerical Methods for Solving Ordinary Differential Equations Philip H. Dybvig Reference: Numerical Methods for Engineers, Chapra and Canale, chapter 25, 2006 Slides designed by Yajun Wang
2
Numerical Solutions Numerical method are used to obtain a graph or a table of the unknown function Most of the Numerical methods used to solve ODE are based directly (or indirectly) on truncated Taylor series expansion Taylor Series methods Runge-Kutta methods Fin500J Topic 7Fall 2010 Olin Business School 2
3
Fin500J Topic 7Fall 2010 Olin Business School 3 Taylor Series Method The problem to be solved is a first order ODE Estimates of the solution at different base points are computed using truncated Taylor series expansions
4
Fin500J Topic 7Fall 2010 Olin Business School 4 Taylor Series Expansion n th order Taylor series method uses n th order Truncated Taylor series expansion
5
Fin500J Topic 7Fall 2010 Olin Business School 5 First Order Taylor Series Method (Euler Method)
6
Fin500J Topic 7Fall 2010 Olin Business School 6 Euler Method
7
Fin500J Topic 7Fall 2010 Olin Business School 7 Interpretation of Euler Method x 0 x 1 x 2 x y0y0 y1y1 y2y2
8
Fin500J Topic 7Fall 2010 Olin Business School 8 Interpretation of Euler Method h x 0 x 1 x 2 x y0y0 y 1 =y 0 +hf(x 0,y 0 ) Slope=f(x 0,y 0 ) hf(x 0,y 0 ) y1y1
9
Fin500J Topic 7Fall 2010 Olin Business School 9 Interpretation of Euler Method h x 0 x 1 x 2 x y0y0 y 1 =y 0 +hf(x 0,y 0 ) Slope=f(x 0,y 0 ) hf(x 0,y 0 ) y1y1 h y 2 =y 1 +hf(x 1,y 1 ) Slope=f(x 1,y 1 ) y2y2 hf(x 1,y 1 )
10
Fin500J Topic 7Fall 2010 Olin Business School 10 High Order Taylor Series methods
11
Fin500J Topic 7Fall 2010 Olin Business School 11 Runge-Kutta Methods (Motivation) We seek accurate methods to solve ODE that does not require calculating high order derivatives. The approach is to a formula involving unknown coefficients then determine these coefficients to match as many terms of the Taylor series expansion
12
Fin500J Topic 7Fall 2010 Olin Business School 12 Runge-Kutta Method
13
Fin500J Topic 7Fall 2010 Olin Business School 13 Taylor Series in One Variable Approximation Error
14
Fin500J Topic 7Fall 2010 Olin Business School 14 Taylor Series in One Variable another look
15
Fin500J Topic 7Fall 2010 Olin Business School 15 Definitions
16
Fin500J Topic 7Fall 2010 Olin Business School 16 Taylor Series Expansion
17
Fin500J Topic 7Fall 2010 Olin Business School 17 Taylor Series in Two Variables xx+h y y+k
18
Fin500J Topic 7Fall 2010 Olin Business School 18 Runge-Kutta Method
19
Fin500J Topic 7Fall 2010 Olin Business School 19 Runge-Kutta Method
20
Fin500J Topic 7Fall 2010 Olin Business School 20 Runge-Kutta Method
21
Fin500J Topic 7Fall 2010 Olin Business School 21 Runge-Kutta Method
22
Fin500J Topic 7Fall 2010 Olin Business School 22 Runge-Kutta Method Alternative Formulas
23
Fin500J Topic 7Fall 2010 Olin Business School 23 Runge-Kutta Methods
24
Fin500J Topic 7Fall 2010 Olin Business School 24 Runge-Kutta Methods
25
Fin500J Topic 7Fall 2010 Olin Business School 25 Runge-Kutta Methods Higher order Runge-Kutta methods are available Higher order methods are more accurate but require more calculations. Fourth order is a good choice. It offers good accuracy with reasonable calculation effort
26
Fin500J Topic 7Fall 2010 Olin Business School 26 Example 1 Second Order Runge-Kutta Method
27
Fin500J Topic 7Fall 2010 Olin Business School 27 Example 1 Second Order Runge-Kutta Method
28
Fin500J Topic 7Fall 2010 Olin Business School 28 Example 1 Summary of the solution Summary of the solution
29
Fin500J Topic 7Fall 2010 Olin Business School 29 Solution after 100 steps
30
Numerically Solving ODE in Matlab Matlab has a few different ODE solvers, Matlab recommends ode45 is used as a first solver for a problem ode45 uses simultaneously fourth and fifth order Runge-Kutta formula (Dormand–Prince) Fin500J Topic 7Fall 2010 Olin Business School 30
31
Numerically Solving ODE in Matlab (Example 1) Fin500J Topic 7Fall 2010 Olin Business School 31 Step 1: Create a M-file for dy/dx as firstode.m function yprime=firstode(x,y); yprime=1+y^2+x^3; Step 2: At a Matlab command window >>[x,y]=ode45(@firstode,[1,2],-4); >> [x,y] Matlab returns two column vectors, the first with values of x and the second with value of y.
32
Numerically Solving ODE in Matlab (Example 1) Fin500J Topic 7Fall 2010 Olin Business School 32 >> plot(x,y,'+')
33
Fin500J Topic 7Fall 2010 Olin Business School 33 Solving a system of first order ODEs Methods discussed earlier such as Euler, Runge- Kutta,…are used to solve first order ordinary differential equations The same formulas will be used to solve a system of first order ODEs. In this case, the differential equation is a vector equation and the dependent variable is a vector variable.
34
Fin500J Topic 7Fall 2010 Olin Business School 34 Euler method for solving a system of first order ODEs Recall Euler method for solving first order ODE.
35
Fin500J Topic 7Fall 2010 Olin Business School 35 Solving a system of n first order ODEs using Euler method Exactly the same formula is used but the scalar variables and functions are replaced by vector variables and vector values functions. Y is a vector of length n F(Y,x) is vector valued function
36
Fin500J Topic 7Fall 2010 Olin Business School 36 Example : Euler method for solving a system of first order ODEs
37
Fin500J Topic 7Fall 2010 Olin Business School 37 Example : RK2 method for solving a system of first order ODEs
38
Fin500J Topic 7Fall 2010 Olin Business School 38 Example : RK2 method for solving a system of first order ODEs
39
Fin500J Topic 7Fall 2010 Olin Business School 39 The general approach to solve high order ODE convertsolve high order ODE convert System of first order ODE solve Second order ODETwo first order ODEs
40
Fin500J Topic 7Fall 2010 Olin Business School 40 Conversion Procedure high order ODE convert System of first order ODE solve 1. Select of dependent variables One way is to take the original dependent variable and its derivatives up to one degree less than the highest order derivative. 2. Write the Differential Equations in terms of the new variables. The equations comes from the way the new variables are defined or from the original equation. 3. Express the equations in matrix form
41
Fin500J Topic 7Fall 2010 Olin Business School 41 Example of converting High order ODE to first order ODEs One degree less than the highest order derivative
42
Fin500J Topic 7Fall 2010 Olin Business School 42 Example of converting High order ODE to first order ODEs
43
Numerically Solving high order ODE in Matlab Fin500J Topic 7Fall 2010 Olin Business School 43 Step 1: First convert the second order equation to an equivalent system of first order ODEs, let z 1 =y, z 2 =y’:
44
Numerically Solving high order ODE in Matlab Fin500J Topic 7Fall 2010 Olin Business School 44 Step 2: Create the following M-file and save it as F.m function zprime=F(x,z) zprime=zeros(2,1); %since output must be a column vector zprime(1)=z(2); zprime(2)=-x*z(1)+exp(x)*z(2)+3*sin(2*x); Step 3: At Matlab prompt >> [x,z]=ode45(@F,[0,1],[2,8]) Since z1(x)=y, to print out the solution y >> [x,z(:,1)]
45
Numerically Solving ODE in Matlab (Example 1) Fin500J Topic 7Fall 2010 Olin Business School 45 To plot y against x >> plot(x, z(:,1)) Because the vector z has first component z1=y
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.