1 / 45

Fin500J Mathematical Foundations in Finance Topic 7: Numerical Methods for Solving Ordinary Differential Equations Phil

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. Numerical Solutions.

artie
Download Presentation

Fin500J Mathematical Foundations in Finance Topic 7: Numerical Methods for Solving Ordinary Differential Equations Phil

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fin500J Mathematical Foundations in Finance Topic 7: Numerical Methods for Solving Ordinary Differential EquationsPhilip H. Dybvig Reference: Numerical Methods for Engineers, Chapra and Canale, chapter 25, 2006 Slides designed by Yajun Wang Fall 2010 Olin Business School

  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 Fall 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 Fall 2010 Olin Business School

  4. Taylor Series Expansion nth order Taylor series method uses nth order Truncated Taylor series expansion Fall 2010 Olin Business School

  5. First Order Taylor Series Method(Euler Method) Fall 2010 Olin Business School

  6. Euler Method Fall 2010 Olin Business School

  7. Interpretation of Euler Method y2 y1 y0 x0 x1 x2 x Fall 2010 Olin Business School

  8. Interpretation of Euler Method Slope=f(x0,y0) y1 y1=y0+hf(x0,y0) hf(x0,y0) y0 x0 x1 x2 x h Fall 2010 Olin Business School

  9. Interpretation of Euler Method y2 y2=y1+hf(x1,y1) Slope=f(x1,y1) hf(x1,y1) Slope=f(x0,y0) y1=y0+hf(x0,y0) y1 hf(x0,y0) y0 x0 x1 x2 x h h Fall 2010 Olin Business School

  10. High Order Taylor Series methods Fall 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 Fall 2010 Olin Business School

  12. Runge-Kutta Method Fall 2010 Olin Business School

  13. Taylor Series in One Variable Approximation Error Fall 2010 Olin Business School

  14. Taylor Series in One Variableanother look Fall 2010 Olin Business School

  15. Definitions Fall 2010 Olin Business School

  16. Taylor Series Expansion Fall 2010 Olin Business School

  17. Taylor Series in Two Variables y+k y x x+h Fall 2010 Olin Business School

  18. Runge-Kutta Method Fall 2010 Olin Business School

  19. Runge-Kutta Method Fall 2010 Olin Business School

  20. Runge-Kutta Method Fall 2010 Olin Business School

  21. Runge-Kutta Method Fall 2010 Olin Business School

  22. Runge-Kutta MethodAlternative Formulas Fall 2010 Olin Business School

  23. Runge-Kutta Methods Fall 2010 Olin Business School

  24. Runge-Kutta Methods Fall 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 Fall 2010 Olin Business School

  26. Example 1Second Order Runge-Kutta Method Fall 2010 Olin Business School

  27. Example 1Second Order Runge-Kutta Method Fall 2010 Olin Business School

  28. Example 1Summary of the solution Summary of the solution Fall 2010 Olin Business School

  29. Solution after 100 steps Fall 2010 Olin Business School

  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) Fall 2010 Olin Business School

  31. Numerically Solving ODE in Matlab (Example 1) 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. Fall 2010 Olin Business School

  32. Numerically Solving ODE in Matlab (Example 1) >> plot(x,y,'+') Fall 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. Fall 2010 Olin Business School

  34. Euler method for solving a system of first order ODEs Recall Euler method for solving first order ODE. Fall 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 Fall 2010 Olin Business School

  36. Example :Euler method for solving a system of first order ODEs Fall 2010 Olin Business School

  37. Example :RK2 method for solving a system of first order ODEs Fall 2010 Olin Business School

  38. Example :RK2 method for solving a system of first order ODEs Fall 2010 Olin Business School

  39. The general approach to solve high order ODE convert solve high order ODE System of first order ODE convert solve Second order ODE Two first order ODEs Fall 2010 Olin Business School

  40. Conversion Procedure convert solve • 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. • 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. • Express the equations in matrix form high order ODE System of first order ODE Fall 2010 Olin Business School

  41. Example of converting High order ODE to first order ODEs One degree less than the highest order derivative Fall 2010 Olin Business School

  42. Example of converting High order ODE to first order ODEs Fall 2010 Olin Business School

  43. Numerically Solving high order ODE in Matlab Step 1: First convert the second order equation to an equivalent system of first order ODEs, let z1=y, z2=y’: Fall 2010 Olin Business School

  44. Numerically Solving high order ODE in Matlab 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)] Fall 2010 Olin Business School

  45. Numerically Solving ODE in Matlab (Example 1) To plot y against x >> plot(x, z(:,1)) Because the vector z has first component z1=y Fall 2010 Olin Business School

More Related