Fall 6 The Stanar Form of a Differential Equation Format require to solve a ifferential equation or a system of ifferential equations using one of the comman-line ifferential equation solvers such as rkfie, Rkaapt, Raau, Stiffb, Stiffr or Bulstoer. For a numerical routine to solve a ifferential equation (DE), we must somehow pass the ifferential equation as an argument to the solver routine. A stanar form for all DEs will allow us to o this. Basic iea: get ri of any secon, thir, fourth, etc. erivatives that appear, leaving only first erivatives. y () Eample + y () y() This DE contains a secon erivative. How o we write a secon erivative as a first erivative? A secon erivative is a first erivative of a first erivative. y () y () Step : STANDARDIZATION Let's efine two functions y () an y () as y () y () an y () y () Then this ifferential equation can be written as y () + y () y () This DE contains functions instea of one, but there is a strong relationship between these two functions y () y ()
So, the original DE is now a system of two DEs, y () y () an y () + y () y () The convention is to write these equations with the erivatives alone on the left-han sie. y () y () y () + y () y () This is the first step in the stanarization process. Step : DEFINE A SINGLE FUNCTION FOR THE NUMERICAL SOLVER y () y () y () + 7 y () y () We have two functions of, y () an y () These functions y an y allow us to efine a single function D Dy (, ) y + 7 y y which specifies for each vector, the corresponing vector of erivative values. This function D is the essential component to be use in solving a ifferential equation numerically. When constructing this function, be sure to use the array subscript to inicate the orer of the erivative. use of rkfie to solve ifferential equations: rkfie(ic,,, npoints, D) This function returns a matri in which the first column contains the points at which the ODE solution is evaluate an the remaining columns contains the corresponing values of the ODE solution(s) an its first n- erivatives. A fourth-orer Runge-Kutta metho is use. ic is a vector of n initial values or a single initial value., are enpoints of the interval on which the solution to ifferential equations will be evaluate. Initial values in y are the values at. npoints is the number of points beyon the initial point at which the solution is to be approimate. This controls the number of rows ( + npoints) in the matri returne by rkfie. D is an n-element vector-value function containing first erivatives of unknown functions. When using this function you will better off by not incluing the units. Units can always be ae after the calculations are one.
Initial Conitions ic npoints Q rkfie( ic,,, npoints, D) Q =....8..8 Q 6......7 6 Q The iea is to change the n-th orer ODE into a system of n couple first-orer ifferential equations Systems of Differential Equations Eample It may be that you are solving a system of equations rather than a single ifferential equation. Consier the following system Define u'' () v () v'' () v () + u()
y () u () y () v () The system of equations becomes the system y () y () an y () y () y () y () y () y () + y () then D( y, ) y y y y + y u' () u'' () v' () v'' () s In this case, we have efine functions so that the even inices correspon to the unknown function u an it erivatives, while the o inices correspon to v. Now that the erivative vector D is set, we'll solve the secon-orer system using Rkaapt. Rkaapt takes the following arguments: Rkaapt(ic, start, en, npts, D) ic - vector of initial conitions. Scalar for a first-orer DE. start, en - enpoints of the solution interval npts - number of approimating points past the initial conition. The result will be a matri containing npts + rows D - the erivative vector ic.. u ( ) v ( ) u' ( ) v' ( ) Initial conition vector D( y, ) y y y y + y u' () v' () u'' () v () v'' () v () + u() Vector-value function containing the erivatives of the unknown functions
Z Rkaapt( ic,,,, D) Rkaapt returns a vector of ata where the first column contains the values of the inepenent variable. The remaining columns contain the function an erivatives evaluate at the corresponing values of the inepenent variable. For a system, the columns are returne in the same orer in which the initial conitions are entere. u v u' v' Z = 6 7 8 9.. -.8.........6.......8.7...6..6...9.7..6.6.8..7..9 Z u Z v Z u' Z v' Z uu Z vv Z...7 u() v() u'() v'()