BMEN 398: MATLAB Module: Higher Order Differential Equations; SIMULINK Fall 2005 Updated 8/21/2005 Hart Higher Order ODEs: (Rao, 2002) Although we can now write MATLAB code to find numerical solutions to (a set of) 1 st order differential equations, many physical systems are governed by higher order differential equations. Fortunately, an ordinary differential equation of order n can always be re-written as a system of n first order ordinary differential equations. Consider a general n th order ODE: a n (x) d n y n + a n1(x) d n1 y n1 +...+ a 1(x) dy + a 0(x)y = g(x) By using the following substitutions, y = y 1 dy = dy 1 = y 2 d 2 y 2 = dy 2 = y 3... d n1 y = dy n1 n1 = y n d n y = dy n n then the original n th order ODE can be written as an equivalent system of n 1 st order ODE s: dy 1 = f 1 (y 1, y 2,..., y n, x) y 2 dy 2 = f 2 (y 1, y 2,..., y n, x) y 3... dy n1 = f n1 (y 1, y 2,..., y n, x) y n dy n = f n (y 1, y 2,..., y n, x) F(y 1, y 2,..., y n, x) or re-written in vector notation as: 1
d y = f ( y, x ) where y = y 1 $ y 2 y n % & ' and f = $ f 1 f 2 f n % & ' Example (Dabney and Harman, 1998): Consider a spring-mass-damper system as shown: Ignoring friction, the governing equation of motion (a 2 nd order differential equation) is: where x = displacement = x = velocity d 2 x = x = acceleration 2 m d 2 x 2 or + c + kx = F mx + c + kx = F and m is mass; c is damping; k is stiffness, and F is a forcing function. In order to solve this, we will re-write the 2 nd order equation as two 1 st order equations: 2
First, write the 2 nd order equation in terms of the 2 nd order derivative term: mx + cx + kx = F x = c m x k m x F now, with 1 2 x 2, then = c m x 2 k m x 1 F This is now just a system of two 1 st order differential equations, and it s a straightforward modification of the programs developed for the cell tissue example to solve. The needed constants are: c = 1.0 k = 2lb/ft m = 5slugs and the initial conditions are: x t =0 = 1 t =0 = 0 MATLAB code to solve these two coupled, 1 st order differential equations is in the code: Lumpmain.m LumpFun.m 3
SIMULINK MATLAB provides an intuitive and visually appealing graphical environment for solution of control systems problems, SIMULINK. The idea is to use a collection of connected function blocks that can be assembled to fashion a wide variety of engineering systems that hides much of the mathematics required to model the system. These function blocks include mathematical operator blocks, and as a brief introduction to SIMULINK, we are going to solve the same spring-dashpot-mass example as above by means of these blocks. This very simple introduction provides the basis to explore SIMULINK, and you may find it particularly useful for the quantitative study physiological systems. To open SIMULINK, first open MATLAB, and type simulink In class we will discover how to open a file, choose appropriate blocks and make connections so that we end up with the following SIMULINK version of the 2 nd order differential equation that represents the spring-dashpot-mass system: We will run this in class, with the output reflected by what is drawn on the scope: 4
References: Chapman, S.J., MATLAB Programming for Engineers, Brooks/Cole Publishers, Third Edition, 2004. Dabney, J.B., Harman, T.L., Student Edition of SIMULINK User s Guide (Version 2) 1998. The Mathworks, Learning MATLAB 7, 1984-2004. S.S. Rao, Applied Numerical Methods for Engineers and Scientists, Prentice Hall, 2002. Associated files: Lumpmain.m LumpFun.m 5