Example: stock market

Ordinary Differential Equations (ODE) in MATLAB

Ordinary Differential Equations (ODE) in MATLABO rdinary Differential Equations (ODE) inMATLABShan HeSchool for Computational ScienceUniversity of BirminghamModule 06-23836: Computational Modelling with MATLABO rdinary Differential Equations (ODE) in MATLABWhat will we learn from the next 5 lecturesIHow to solve ODEs using to model biological systems using ODEs in to analyse ODEs using bifurcation and chaos using of bifurcation and chaos to biological Differential Equations (ODE) in MATLABO utlineOutline of TopicsConcepts about ODES olving ODE in MATLABODE Solvers in MATLABS olving linear ODEs in MATLABS olving high order ODEs in MATLABS olving ODEs in MATLAB .

Ordinary Di erential Equations (ODE) in MATLAB Solving ODE in MATLAB ODE Solvers in MATLAB Solution to ODE I If an ODE is linear, it can be solved by analytical methods. I In general, an nth-order ODE has n linearly independent solutions. I Any linear combination of linearly independent functions solutions is also a solution.

Tags:

  Matlab

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Ordinary Differential Equations (ODE) in MATLAB

1 Ordinary Differential Equations (ODE) in MATLABO rdinary Differential Equations (ODE) inMATLABShan HeSchool for Computational ScienceUniversity of BirminghamModule 06-23836: Computational Modelling with MATLABO rdinary Differential Equations (ODE) in MATLABWhat will we learn from the next 5 lecturesIHow to solve ODEs using to model biological systems using ODEs in to analyse ODEs using bifurcation and chaos using of bifurcation and chaos to biological Differential Equations (ODE) in MATLABO utlineOutline of TopicsConcepts about ODES olving ODE in MATLABODE Solvers in MATLABS olving linear ODEs in MATLABS olving high order ODEs in MATLABS olving ODEs in MATLAB .

2 Advanced topicsOrdinary Differential Equations (ODE) in MATLABC oncepts about ODEWhat is ODEAn Ordinary Differential Equation (ODE) is an equation involvinga function and its Differential Equations (ODE) in MATLABC oncepts about ODED efinition of ODEIL etybe an unknown function =dydxbe the first derivative with respect (n)=dnydxnbe thenth derivative with respect a given functionIThen an ODE of ordernis an equation of the form:F(x,y,y ,..,y(n)) = 0 Ordinary Differential Equations (ODE) in MATLABC oncepts about ODEL inear ODE and Homogeneous Linear ODEIA ODE is said to be linear ifFcan be written as a linearcombination of the derivatives ofytogether with a constantterm, all possibly depending on x.

3 An(x)yn+an 1(x)yn 1+ +a1(x)y +a0y=r(x)or more concisely,yn=n 1 i=0ai(x)y(i)+r(x)whereai(x) andr(x) are continuous functions inxand thefunctionr(x) is called the source linear ODE is said to be homogeneous ifr(x) = 0,otherwise it is called non-homogeneous or Differential Equations (ODE) in MATLABS olving ODE in MATLABODE Solvers in MATLABS olution to ODEIIf an ODE is linear, it can be solved by analytical general, annth-order ODE hasnlinearly linear combination of linearly independent functionssolutions is also a an ODE isnotlinear, most of the case itcannotbe solvedexactly: we will use MATLAB to obtain approximate solutionsOrdinary Differential Equations (ODE) in MATLABS olving ODE in MATLABODE Solvers in MATLABODE Solvers in MATLABIM atlab has several different ODE solvers for the numericalsolution of ODEs.

4 Iode45: based on an explicit Runge-Kutta (4, 5) formula andthe Dormand-Prince : based on an explicit Runge-Kutta (2, 3) formula andthe Bogacki and Shampine choose according to order of accuracy and the type ofsystems (stiff or nonstiff).IRule of thumb: Always Differential Equations (ODE) in MATLABS olving ODE in MATLABODE Solvers in MATLABHow to use MATLAB ODE SolversIThe MATLAB ODE solvers can be called as a function:[T,Y] = ode**(@odefun,tspan,y0,options)I@odefun: Function handle of the ODE functionItspan: Interval of integration, [t0,tfinal].

5 Iy0: Initial : Optional ODE functionodefundefine the ODEs:function [dy] = odefun(t, y, parameters) Ordinary Differential Equations (ODE) in MATLABS olving ODE in MATLABS olving linear ODEs in MATLABS olving linear ODE in MATLABOne simple example:{u =du(x)dx=u(x) +v(x)v =dv(x)dx=u(x)Analytical solution can be obtained, but how to solve it inMATLAB numerically? Ordinary Differential Equations (ODE) in MATLABS olving ODE in MATLABS olving linear ODEs in MATLABS olving linear ODE in MATLABS teps for solving this equation numerically in MATLAB :IStep 1: Create a MATLAB function that defines the ODEs1function dy = simple_ode(t,y)2% function to be integrated3dy = zeros(2,1);4dy(1) = y(1) + y(2);5dy(2) = y(1).}

6 Ordinary Differential Equations (ODE) in MATLABS olving ODE in MATLABS olving linear ODEs in MATLABS olving linear ODE in MATLABIStep 2: Call a numerical solver provided in MATLAB , ,[T,Y] = ode45(odefun,tspan,y0)1tspan = [0 10];2y0 = [1 0];3[X,Y] = ode45(@simple_ode,tspan,y0); Ordinary Differential Equations (ODE) in MATLABS olving ODE in MATLABS olving high order ODEs in MATLABR eduction of ODE orderIRecall an ODE of the general form:F(x,y,y ,..,y(n)) = 0 IWe said this system is an ODE of Differential equation of orderncan be reduced to asystem ofnfirst-order (n= 1) Differential do so because high order ODE (n>1) is difficult to ODE solvers cannot handle higher order ODE!

7 Ordinary Differential Equations (ODE) in MATLABS olving ODE in MATLABS olving high order ODEs in MATLABR eduction of ODE orderMethods:IWe will use a second order ODE as an example:{x = ye( t/5)+y e( t/5)+ 1y = 2 sin(t)IStep 1: Introduce a new variable that equals the firstderivative of the free variable in the second order equation:z=y IStep 2: Taking the derivative of each side yields the following:z =y Ordinary Differential Equations (ODE) in MATLABS olving ODE in MATLABS olving high order ODEs in MATLABR eduction of ODE orderMethods:IStep 3: Substituting the second order ODE withzandz : x = ye( t/5)+ze( t/5)+ 1z = 2 sin(t)y =zOrdinary Differential Equations (ODE) in MATLABS olving ODE in MATLABS olving high order ODEs in MATLABS olve high order ODE in MATLABM ethods:IStep 4: Write a MATLAB function to define theODE:1function dy = high_order_ode_example(t,x)2% x(1) = x3% x(2) = y4% x(3) = z5dy = [-x(2)*exp(-t/5) +.]}

8 6x(3)*exp(-t/5) + 1;7x(3);8-2*sin(t)]9endOrdinary Differential Equations (ODE) in MATLABS olving ODE in MATLABS olving high order ODEs in MATLABS olve high order ODE in MATLABM ethods:IStep 5: evaluate the system of Equations using ODE45:1t0 = 5; % Start time2tf = 20; % Stop time3x0 = [1 -1 3] % Initial conditions4[t,s] = ode45(@ho_ode,[t0,tf],x0);5x = s(:,1);6y = s(:,2);7z = s(:,3);8plot(t,s); Ordinary Differential Equations (ODE) in MATLABS olving ODE in MATLABS olving ODEs in MATLAB : Advanced topicsStiffness of ODE equationsIStiffness is a subtle, difficult, and important concept in thenumerical solution of Ordinary Differential A problem is stiff if the solution being sought varies slowly,but there are nearby solutions that vary rapidly, so thenumerical method must take small steps to obtain satisfactoryresults.

9 IExample:y =y2 y3y(0) = 0 t 2 IIf we weren t concerned with efficiency of ODE solver, wewouldn t be concerned about Differential Equations (ODE) in MATLABS olving ODE in MATLABS olving ODEs in MATLAB : Advanced topicsPassing parameters to ODEsIBy passing the value to ODE function, we can change thecoefficients in ODEs each time we call the ODE need to define the parameters in the ODE function header:1function dy = ode_pv(t,y,A)2% function to be integrated3dy = zeros(2,1);4dy = A*yOrdinary Differential Equations (ODE) in MATLABS olving ODE in MATLABS olving ODEs in MATLAB : Advanced topicsPassing parameters to ODEsICall the ODE solver and pass the parameter to the ODEfunction:1tspan = [0 10];2initvalue = [1 0];3option = [];4for ii=-10:45A = [1 ii; 2 -1];6[t,y] = on;9plot(t, y).

10 10endOrdinary Differential Equations (ODE) in MATLABS olving ODE in MATLABS olving ODEs in MATLAB : Advanced topicsEventsIRecall syntax of the ODE solvers:[T,Y] = ode**(@odefun,tspan,y0,options)IWe generally assumetspanis known, ,t0 t tfinalIBut sometimes it is also important to : a ball is falling because of gravity, when does it hitthe ground?IEquations:y =g= (t) is the height of the object at timetIThe question: for whattdoesy(t) = 0? We can use Differential Equations (ODE) in MATLABS olving ODE in MATLABS olving ODEs in MATLAB : Advanced topicsDefine eventsIDefine the ODE function:1function dydt = ode_ball(t,y)2dydt = [y(2); ];IDefine event function for this problem:1function [value,isterminal,direction].


Related search queries