Download as pdf
Download as pdf
You are on page 1of 7
tax. The basic nple, a,‘left’) = 10.4. pitlerential Equations eis Test Your Understanding T10.3-6 Use MATLAB to find the first three nonzero terms in the Taylor series for cos x. (Answer: 1 ~ x2/2 + x4/24.) 1103-7 Use MATLAB to find a formula for the sum (Answer: m4/4 — m3/2 + m?/4.) 710.3-8 Use MATLAB to evaluate 1 Yeos(an) (Answer: 0.) T10.3-9 Use MATLAB to evaluate (Answer: 2/75.) 10.4 Differential Equations {A first-order ordinary differential equation (ODE) can be written in the form dy Fa sey where ¢ is the independent variable and y is a function oft. A solution to such an equation is a function y = g(¢) such that dg/dt = f(t, g), and the solution will contain one arbitrary constant. This constant becomes determined when we apply an additional condition of the solution by requiring that the solution have a specified value y(t) when ¢ =f. The chosen value fis often the smallest, or __ _ starting value, of ¢, and if so, the condition is called the initial condition (quite INITIAL often f; = 0). The general term for such a requirement is a boundary condition, CONDITION and MATLAB lets us specify conditions other than intial conditions. Forexample, ‘we can specify the value of the dependent variable at ¢ = fa, where f2 > BOUNDARY Methods for obtaining a numerical solution to differential equations were CONDITION covered in Chapter 8. However, we prefer to obtain an analytical solution when- ever possible because it is more general and thus more useful for designing engineering devices or processes. o16 CHAPTER 10 Symbolic Processing with MATLAB A second-order ODE has the following form: =7(on®) Its solution will have two arbitrary constants that can be determined once tw Additional conditions are specified, These conditions are often the specified values of y and dy/dt at ¢ = 0. The generalization to third-order and higher equations is straightforward. ‘We will occasionally use the following abbreviations for the first-and second. order derivatives: dy ey at ar MATLAB provides the dsolve function for solving ordinary differential equations. Its various forms differ according to whether they are used to solve single equations or sets of equations, whether or not boundary conditions are specified, and whether or not the default independent variable t is acceptable. Note that tis the default independent variable and not x as with the other symboli¢ fonetions. The reason is that many ODE models of engineering applications have time ¢ as the independent variable. Solving a Single Differential Equation The dsolve function's syntax for solving a single equation is solve ("ean"). The function retums a symbolic solution of the ODE specified by the symbolic expression eqn. Use the uppercase letter D to represent the first derivative, use D2 to represent the second derivative, and so on. Any character immediately following the differentiation operator is taken to be the dependent variable. Thus Dw represents dw/dt. Because of this syntax, you cannot use "uppercase D as symbolic variable when using the dsol ve function, ‘The arbitrary constants in the solution are denoted by C1, C2, and so on. The ‘number of such constants is the same as the order of the ODE. For example, the equation dy ate 12 has the solution y(t) =6 + Cie The solution can be found with the following session. Note that you need not declare y to be symbolic prior to using dsolve. >>dsolve('Dy+2*y=12") ans = 6+C1*exp(-2*t) once two, ied values, equations id second- ifferential d to solve tions are cceptable. rsymbolic tions have dsolve ecified by it the first character 1 need not 410.4. Difleertal Equations ‘There can be symbolic constants in the equation. For example, ay ay = sin(at) has the solution ‘os(at) yO= +c Itcan be found as follows: ve("Dy=sin(a*t)") (-cos(a*e) +Cl*a) /a Here is a second-order example: dy ae The solution y(t) = Cie +C2e~* can be found withthe following session: dsolve(/Day=c*2*y") ans = Cltexp(-ctt) "+ C2*exp(c*t) Solving Sets of Equations Sets of equations can be solved with dsol ve. The appropriate syntax is Gsolve (ean1", ‘eqn2", ...). The function returns a symbolic solution of the set of equations specified by the symbolic expressions eqn1 and eqn2. For example, the set ax Hanya a ty ay B aa 43 B a -an43y has the solution x(4) = Cie™ cost + Cae sind, y(t) = —Cie™ sind + Cze* cos 4t. The session is >> Lx, y] = dsolve(‘Dx=3*x+4*y", ‘Dy=-4*x+3*y") x = Cltexp(3*t) *cos (4*t) +C2*exp(3*t) *sin(4*t) y = -Cl*exp(3*t) *sin(4*t) +C2*exp(3*t) *cos (4*t) Specifying Initial and Boundary Con Conditions on the solutions at specified values of the independent variable can be handledas follows. Theformdsolve(’eqn’, ‘condl’, ‘cond2‘,...) retums a symbolic solution of the ODE specified by the symbolic expression ‘eqn, subject to the conditions specified in the expressions cond, cond2, and ions 617 o8 CHAPTER 10 Symbolic Processing with MATLAB, so on. If y is the dependent variable, these conditions are specified as follows: y(a) = b,Dy(a) = ¢,D2y(a) = d,andsoon. These correspond to y(a), 3(a), 9(a), and so on. If the number of conditions is less than the order of the ‘equation, the returned solution will contain arbitrary constants C1, C2, and s0 on, For example, the problem dy Fp =sin(bs), y(0)=0 has the solution y(t) = [1 — cos(br)]/b. It can be found as follows: >edsolve(’Dy=sin(b*t)’, ‘y(0)=0") ans = ~cos (b*t) /b+1/b ‘The problem @y “i Y= cy, yO)=1, 50) qe YO i has the solution y(t) = (e + e~*?)/2. The session is vedsolve (Day=e"24y" "y(0) 1", "Dy (0)=0") & 1/2*exp(c*t) +1/2*exp(-c*t) can be used. For example, Arbitrary boundary conditions, such as y(0) = the solution of the problem dy qton The session is >edsolve(‘Dysaty=b’, 'y (0 L/a*btexp(-a*t) *(-1/a*b+c) Plotting the Solution ‘The ezplot function can be used to plot the solution, just as with any other symbolic expression, provided no undetermined constants such as C1. are present. For example, the problem 2 + oy =10+45in(4s), (0) = 0 has the solution 104. Differential Equations 1 eos 91029 sin -2529 wnt -100) follows 2 tora), r of the | soon | oa aa SE aa zane) Figure 10.44 Plot ofthe solution of j + 10y = 10-4 4sin4, 0) © FE tresessionis >oy = solve (/Dy110*y=10+4*sin(4*t) “, “y(0)=0") go 1-4/29*cos(4*t) + 10/29*sin(4*t) -25/29%exp (-10*t) >eezplot (y),axis({0 5 0 2]) The plot is shown in Figure 10.41. Sometimes the ezplot function uses too few values of the independent variable and thus does not produce a smooth plot. To override the spacing chosen “afi by the ezp1ot function, you can use the subs function to substitute an array of values for the independent variable. Note that you must define t to be a symbolic < F& _variable. For example, you can continue the previous session as follows: ny other MP >>syms t present. | dex = [0:0.05:5]; >>P = subs(y,t.x); >eplot (x,P),axis([0 5 0 2]), xlabel('t’) e Equation Sets with Boundary Conditions : Sets of equations with specified boundary conditions can be solved as follows. © (BE Thefunctiondsolve(’eqni’, 'eqn2’,...,’condi’, ‘cond2’,...) CHAPTER 10 Symbolic Processing wih MATLAB retums a symbolic solution of a set of equations specified by the symbolic ex- pressions egn1, eqn2, and so on, subject to the initial conditions specified in the expressions cond, cond2, and so on. For example, the problem dx Xaaxtdy, x0) =0 Fea3et4y, x0) dy Fant 3x Oat has the solution (6) = e* sin(4t), y(0) = €* cos(4t) ‘The session is pedsolve("Dx=3*x+4ty’, ‘Dy=-4*x+3*y/, "x (0) 20%, "y (0) =1") bxy) = x = exp(3*t)*sin(4*t), y = exp(3*t) *cos (4*t) 4 It is not necessary to specify only initial conditions. The conditions can be specified at different values of t. For example, to solve the problem ay +9 ar 0) jen) =2 the session is >>dsolve("D2y+9*y=0", ‘y(0)=1", "Dy (pi) =2') -2/3*sin(3*t) +cos(3*t) Using Other Independent Variables ‘Although the default independent variable is t, you can use the following syn- tax to specify a different independent variable. The function dsolve (‘egn1", ‘eqn’, -.., ‘condi’, ’cond2’, ..., ’x’) returns a symbolic solution of a set of equations where the independent variable is For example, the solution of the equation Beawe=2 is v(x) = 6 + Cre. The session is >edsolve(‘Dv+2*v=12",'x') 6+exp(-2*x) *C1 Ly can be g syn- nl’, mbolic 10.4. Ditfeertial Equations Test Your Understanding T10.4-1 Use MATLAB to solve the equation Check the answer by hand or with MATLAB. (Answer: y(¢) = C1 cos(bt) + C2 sin(br).) T10.4-2 Use MATLAB to solve the problem yO) =1, (0) =0 Check the answer by hand or with MATLAB. (Answer: y(t) = cos(bt).) Solving Nonlinear Equations MATLAB‘can solve many nonlinear first-order differential equations. For exam- ple, the problem dy at can be solved with the following session yQ)=1 (104-1) >>dsolve ( ‘Dy: 2+ (exp (4*t-Log (-1/3) ) +1) / (-L¥exp(4*t-Log(-1/3))) >>simple (ans) -y"2", ty(O)=1") 28 (3*exp(4*t) -1) /(1+3*exp (4*t) ) which is equivalent to Not all nonlinear equations can be solved in closed form. For example, the following equation is the equation of motion of a specific pendulum. + 9sin0) 0% yQ=1 =O ‘The following session generates a message that a solution could not be found. >edsolve (‘D2y+9*sin(y)=0", 'y(O)=1", “Dy (0)=0") oat

You might also like