# # # SOLVING DIFFERENTIAL EQUATIONS SYMBOLICALLY # # WITH DSOLVE # # W. E. Boyce # Rensselaer Polytechnic Institute # 04/15/94 # # PURPOSE: To illustrate the use of dsolve to find exact solutions of many # differential equations or systems of equations, with or without initial # conditions. # # # NOTE. Maple has a powerful symbolic differential equation solver called dsolve. # This command directs Maple to seek an exact symbolic expression for the solution # of a given differential equation, or a system of differential equations, with or # without initial conditions. Of course, many differential equations do not have # such exact symbolic solutions, at least not in terms of the usual well-known # functions, so for these equations other Maple commands may be more helpful. # Nevertheless, dsolve works very well for many linear equations and for some # nonlinear ones. The examples below indicate some of the possibilities for using # dsolve effectively. # # NOTE. dsolve has options that request Maple to use Laplace transforms, power # series, or a numerical algorithm, respectively. # The laplace option is particularly useful for certain initial value problems # having a discontinuous or impulsive forcing function. The series and numeric # options are most useful in those cases where an exact symbolic solution is not # available. We do not discuss any of these options here. # # NOTE. Further information about dsolve can be obtained by issuing the command # `?dsolve'. # # # # IMPORTANT NOTE: dsolve insists that coefficients be entered as rational, rather # than floating point, numbers. For example, you should enter a coefficient as 1/2 # or 1/4, rather than 0.5 or 0.2. # # # # # EXAMPLE 1. A FIRST ORDER LINEAR EQUATION # # Find the general solution of the differential equation # # dy/dt = -2 + sin(t) - (1/4)y. # # Also find the solution that satisfies the initial condition # y(0) = 2. # # # SOLUTION. The first step is to enter the differential equation. # > eq1 := diff(y(t),t) = -2 + sin(t) - 1/4*y(t); d eq1 := ---- y(t) = - 2 + sin(t) - 1/4 y(t) dt # Now dsolve can be used to find the general solution of this equation. In its # simplest form the command has two arguments; the first is the equation to be # solved and the second is the variable to be solved for. # > dsolve(eq1,y(t)); 16 y(t) = - 8 - ---- cos(t) + 4/17 sin(t) + exp(- 1/4 t) _C1 17 # # This is the general solution of the given differential equation. Note that Maple # writes the arbitrary constant as _C1, and that in this case the constant follows # the term exp(-t/4) that it multiplies. # # To find the solution that also satisfies the initial condition, we include the # initial condition in the dsolve command, using braces to delimit the problem to # be solved. Also we assign the name sol to the result. # > sol := dsolve({eq1,y(0)=2},y(t)); 16 186 sol := y(t) = - 8 - ---- cos(t) + 4/17 sin(t) + --- exp(- 1/4 t) 17 17 -------------------------------------------------------------------------------- # We can now assign a name, if we wish, to the expression for y(t) on the right # side of the last result, as follows: # > y1 := rhs(sol); 16 186 y1 := - 8 - ---- cos(t) + 4/17 sin(t) + --- exp(- 1/4 t) 17 17 -------------------------------------------------------------------------------- # This enables us to perform operations on the solution y1 of the initial value # problem. For instance, we can evaluate y1 at a given value of t, or we can # plot y1 on some given t interval. # > evalf(subs(t=4,y1)); -3.537843293 -------------------------------------------------------------------------------- > plot(y1,t=0..20,title=`Figure 1`); -------------------------------------------------------------------------------- # # ** Maple V Graphics ** # # # # # # # # EXAMPLE 2. A SECOND ORDER LINEAR HOMOGENEOUS EQUATION # # Solve the equation # # y'' - 2y' - 4y = 0. # # Find the general solution and also the solution that satisfies the initial # conditions y(0) = 2, y'(0) = -7/4. # # # SOLUTION: Again the first step is to enter the differential equation. In the # following command note that the first term the second derivative is entered using # t$2. This causes the differentiation operation to be executed twice. # > eq2 := diff(y(t),t$2) - 2*diff(y(t),t) - 4*y(t) = 0; / 2 \ | d | / d \ eq2 := |----- y(t)| - 2 |---- y(t)| - 4 y(t) = 0 | 2 | \ dt / \ dt / -------------------------------------------------------------------------------- > dsolve(eq2,y(t)); 1/2 1/2 y(t) = _C1 exp((1 + 5 ) t) + _C2 exp(- (- 1 + 5 ) t) -------------------------------------------------------------------------------- # This is the general solution. Note that it contains two exponential terms, each # multiplied by an arbitrary constant. One of the exponentials is positive, and so # grows with increasing t, while the other is negative, and decays as t increases. # # Now we solve the initial value problem. To enter the second initial condition, # denote y'(0) by D(y)(0). We will assign the name y2 to this solution, # combining the dsolve and rhs commands. # > y2 := rhs(dsolve({eq2,y(0) = 2,D(y)(0)=-7/4},y(t))); 1/2 1/2 1/2 1/2 y2 := (- 3/8 5 + 1) exp((1 + 5 ) t) + (3/8 5 + 1) exp(- (- 1 + 5 ) t) -------------------------------------------------------------------------------- # To see the graph of this solution: # > plot(y2,t=0..2,y=0..3,title=`Figure 2`); -------------------------------------------------------------------------------- # # ** Maple V Graphics ** # # # Observe that the positive exponential term causes the solution to grow rapidly. # # # # # # EXAMPLE 3. A SECOND ORDER LINEAR NONHOMOGENEOUS EQUATION # # Find the general solution of the equation # # y'' + 4 y' + 5 y = 3 exp(-t) + 4 sin(3t). # # Also find the solution satisfying the initial conditions # # y(0) = 3/2, y'(0) = 2, # # and plot its graph. # # # SOLUTION. As in the preceding examples we find the general solution by entering # the equation and then using dsolve. # > eq3 := diff(y(t),t$2)+4*diff(y(t),t)+5*y(t)=3*exp(-t)+4*sin(3*t); / 2 \ | d | / d \ eq3 := |----- y(t)| + 4 |---- y(t)| + 5 y(t) = 3 exp(- t) + 4 sin(3 t) | 2 | \ dt / \ dt / -------------------------------------------------------------------------------- > sol := dsolve(eq3,y(t)); sol := y(t) = 3/2 exp(- t) - 2/5 sin(t) cos(4 t) + 1/5 sin(t) sin(4 t) 3 - 1/2 sin(t) cos(2 t) + 1/2 sin(t) sin(2 t) - 13/5 cos(t) 2 5 4 - 13/5 cos(t) sin(t) + 7/10 cos(t) + 8/5 cos(t) + 16/5 cos(t) sin(t) + _C1 exp(- 2 t) sin(t) + _C2 exp(- 2 t) cos(t) -------------------------------------------------------------------------------- # The two terms that involve -C1 and _C2 form the general solution of the # homogeneous equation, while the other terms are a particular solution of the # nonhomogeneous equation. The term in sol that contains exp(-t) arises from the # corresponding term in the forcing function. The remaining trigonometric terms in # sol come from the sin(3t) term in the forcing function. If we solved this # equation by hand we would expect to get only two trigonometric terms, one in # sin(3t) and the other in cos(3t). We can cause Maple to write the solution in # this simpler form in the following way. # > combine(sol,trig); y(t) = 3/2 exp(- t) - 1/10 sin(3 t) - 3/10 cos(3 t) + _C1 exp(- 2 t) sin(t) + _C2 exp(- 2 t) cos(t) -------------------------------------------------------------------------------- # This is the form of the solution that we would obtain by hand, using # the method of undetermined coefficients. # # Now let us use the initial conditions as well. # > init := y(0) = 3/2, D(y)(0) = 2; init := y(0) = 3/2, D(y)(0) = 2 -------------------------------------------------------------------------------- > sol := dsolve({eq3,init},y(t)): -------------------------------------------------------------------------------- > y3 := combine(rhs(sol),trig); y3 := 3/2 exp(- t) - 1/10 sin(3 t) - 3/10 cos(3 t) + 22/5 exp(- 2 t) sin(t) + 3/10 exp(- 2 t) cos(t) -------------------------------------------------------------------------------- # This is the solution to the given initial value problem. Note that values have # been assigned to the arbitrary constants that appeared in the previous expression # for y(t). # # What should we expect its graph to look like? The second and third terms depend # only on sin(3t) and cos(3t), so they represent a steady oscillation of frequency # 3, or of period 2Pi/3. The other terms all include a negative exponential # factor, so they contribute significantly only when t is small, and then tend to # zero as t becomes large. The graph then is a somewhat complicated curve for # small t, but approaches a simple oscillation as t increases. To confirm this, we # ask for a plot. # > plot(y3,t=0..15,title=`Figure 3`); -------------------------------------------------------------------------------- # # # ** Maple V Graphics ** # # # To appreciate fully what Maple has done on this example, you should think about # what you would have had to do to obtain the same results by hand. # # # # # # EXAMPLE 4. Find the general solution of the equation # # y'''' + y''' + y'' - 9 y' - 10 y = 0, # # and also find the solution satisfying the initial conditions # # y(0) = 1, y'(0) = 2, y''(0) = -1, y'''(0) = -3. # # # SOLUTION. We proceed as in the preceding examples. # > eq4 := diff(y(t),t$4) + diff(y(t),t$3) + diff(y(t),t$2) - 9*diff(y(t),t) - 10*y(t) = 0; # # # / 4 \ / 3 \ / 2 \ | d | | d | | d | / d \ eq4 := |----- y(t)| + |----- y(t)| + |----- y(t)| - 9 |---- y(t)| - 10 y(t) = 0 | 4 | | 3 | | 2 | \ dt / \ dt / \ dt / \ dt / -------------------------------------------------------------------------------- > dsolve(eq4,y(t)); y(t) = _C1 exp(2 t) + _C2 exp(- t) + _C3 exp(- t) sin(2 t) + _C4 exp(- t) cos(2 t) -------------------------------------------------------------------------------- # This is the general solution. Its form indicates that two roots of the # characteristic polynomial are real (2 and -1) and that the other two are complex # conjugates (-1 + 2I and -1 -2I). # # Now we enter the initial conditions. Note that the second derivative is # expressed by (D@@2) and similarly for the third derivative. The parentheses # around (D@@2) are essential. # > init := y(0)=1, D(y)(0)=2, (D@@2)(y)(0)=-1, (D@@3)(y)(0)=-3; (2) (3) init := y(0) = 1, D(y)(0) = 2, D (y)(0) = -1, D (y)(0) = -3 -------------------------------------------------------------------------------- > y4 := rhs(dsolve({eq4,init},y(t))); 11 y4 := 1/3 exp(2 t) + ---- exp(- t) + exp(- t) sin(2 t) - 1/4 exp(- t) cos(2 t) 12 -------------------------------------------------------------------------------- # What do you think the graph of this solution looks like? Once you have formed an # opinion, ask Maple for a plot to confirm your conclusion. # # # # EXAMPLE 5. Find the general solution of the system # # dx/dt = -2 x + y, dy/dt = x - 2 y. # # Also find the solution that satisfies the initial conditions x(0) = 0, y(0) = 2. # # # # SOLUTION. # > sys := diff(x(t),t) = -2*x(t)+y(t), diff(y(t),t) = x(t) - 2*y(t); d d sys := ---- x(t) = - 2 x(t) + y(t), ---- y(t) = x(t) - 2 y(t) dt dt # > dsolve({sys},{x(t),y(t)}); {x(t) = _C1 exp(- t) - _C2 exp(- 3 t), y(t) = _C1 exp(- t) + _C2 exp(- 3 t)} # # Observe that both x(t) and y(t) are linear combinations of the same two # exponential functions, and that there are only two distinct arbitrary constants # in the solution. # # Here is the solution of the initial value problem. # > dsolve({sys,x(0)=0,y(0)=2},{x(t),y(t)}); {x(t) = exp(- t) - exp(- 3 t), y(t) = exp(- t) + exp(- 3 t)} # # # # NOTE: Solving a linear homogeneous equation with constant coefficients, or a # system of such equations, of higher than second order is not necessarily a simple # problem, even for Maple. The main mathematical task is to find the roots of the # characteristic polynomial. Equations for which the roots are rational (real or # complex) are handled with relative ease by Maple, but other equations may lead to # very slow response times, or may even cause the system to fail. This reflects # the fact that such problems may be very difficult. Some of these more difficult # problems are explored in another worksheet. # # # # # PROBLEMS # # In each of the following problems use dsolve to find the general solution of the # given differential equation. If initial conditions are given, also find the # solution that satisfies them. Plot this solution. # # 1. dy/dt = t + exp(-2t) + 3y, y(0) = 2 # # 2. dy/dt = 3 sin(t) + 1 - y, y(0) = -1 # # 3. y'' + (5/2)y' + y = 0, y(0) = 2, y'(0) = 3 # # 4. y'' + 6y' + 10y = 0, y(0) = 1, y'(0) = 1 # # 5. y'' + (5/2)y' + y = 3 cos(2t) + 6 exp(-2t), # # y(0) = 2, y'(0) = 3 # # 6. y'' + 6y' + 10y # # = 5 exp(-3t)cos(t) + 2 exp(-t)cos(3t), # # y(0) = 1, y'(0) = 2 # # 7. y''' + 3y'' + 3y' + 2y = 0, # # y(0) = 2, y'(0) = -1, y''(0) = 3 # # 8. y'''' + 4y''' + 10y'' + 11y' + 10y = 0, # # y(0) = 2, y'(0) = 3, y''(0) = -1, y'''(0) = 0 # # 9. y''' + 3y'' + 3y' + 2y # # = exp(-t)sin(t) + 3t^2 - 4t + 5, # # y(0) = 2, y'(0) = -1, y''(0) = 3 # # 10. dx/dt = 3x - 2y, dy/dt = 2x - 2y, # # x(0) = 3, y(0) = 2 # # 11. dx/dt = x - 5y, dy/dt = x - 3y, # # x(0) = 3, y(0) = 2 # # 12. dx/dt = 2x - 5y, dy/dt = x - 2y, # # x(0) = 3, y(0) = 2 # # #