# # A FIRST ORDER LINEAR DIFFERENTIAL EQUATION # # W. E. Boyce # Rensselaer Polytechnic Institute # 04/15/94 # # PURPOSE: To show how Maple can be used to investigate a first order # linear differential equation, using both graphical and analytical # methods. # # EXAMPLE. Consider the first order linear differential equation # # dy/dt = - 2 + t - y. # # (a) Draw the direction field for this equation and plot several # solutions. # # (b) Also solve the equation analytically and find the solution that # satisfies the initial condition y(0) = 0. # # SOLUTION. We will use the Maple command `DEplot' to draw the # direction field. In order to use this command we first call up the # DEtools package. # > with(DEtools); [DEnormal, DEplot, DEplot3d, Dchangevar, PDEchangecoords, PDEplot, autonomous, convertAlg, convertsys, dfieldplot, indicialeq, phaseportrait, reduceOrder, regularsp, translate, untranslate, varparam] # # This command loads the DEtools package and lists the commands that it # contains. # # Information about any of these commands can be obtained online through # Maple's help facility. For example, the command ?DEplot will # produce information about DEplot. # # (a) The first step in solving the problem is to enter the # differential equation. This can be done in several ways, as # described in the help screen. We will do it as shown in the next # command. # > eq1 := diff(y(t),t) = - 2 + t - y(t); d eq1 := -- y(t) = -2 + t - y(t) dt # # The following DEplot command will produce a direction field for this # equation. The first argument is the name of the equation, the second # is a list (enclosed in square brackets) of the variables with the # independent variable first, and the third and fourth are the # horizontal and vertical dimensions of the rectangle in which the # direction field will be drawn. The `arrows' option directs Maple to # draw a direction field using THIN arrows. (It is also possible to # request SLIM or THICK arrows.) The title option is not essential but # can be used to label the plot. # > DEplot(eq1,[y(t)],t=0..6,y=-2..2,arrows=THIN,title=`Figure 1`); # To plot a solution through a given point, we need only to specify the # point. For example, to plot the solution through the origin we modify # the preceding DEplot command as follows. # > DEplot(eq1,[y(t)],t=0..6,{[0,0]},y=-2..2,arrows=THIN,title=`Figure > 2`); # Note that the coordinates of the initial point are enclosed in # brackets, and then in curly braces. Furthermore, the initial point # must occur as the fourth argument, that is, between the horizontal and # vertical dimensions of the rectangle. If you want only the solution # and not the direction field in the background, omit the `arrows' # option. # # If you want Maple to choose the vertical dimension of the rectangle, # you can also omit the y specification. For a steeply rising (or # falling) curve this may lead to a larger y interval than you want. # # Sometimes you may want to plot the solution through each of several # initial points. One way to do this is to list the coordinates of each # point in brackets and then to enclose the entire collection of points # in braces. This would replace the {[0,0]} in the last DEplot # command. Often it is easier to use Maple's `seq' (for sequence) # command to produce the list of points. # > init := seq([0,0.5*i],i=-4..4); init := [0, -2.0], [0, -1.5], [0, -1.0], [0, -.5], [0, 0], [0, .5], [0, 1.0], [0, 1.5], [0, 2.0] # # This produces a list of nine points, spaced 0.5 apart on the y axis, # and names `init'. These points can now be inserted in the DEplot # command; note the braces around init. # > DEplot(eq1,[y(t)],t=0..6,{init},y=-2..2,arrows=THIN,title=`Figure 3`); # Another option that is sometimes helpful is used to modify the grid on # which the direction field is calculated. The default is a 20 by 20 # grid, producing 21 arrows in each row or column. To change this grid # insert the option dirgrid=[m,n] in the DEplot command. This will # produce a direction field on an m by n grid. For example, # > DEplot(eq1,[y(t)],t=0..6,y=-2..2,dirgrid=[15,10],arrows=THIN); # # produces a direction field on a 15 by 10 grid. # # # ANALYTICAL SOLUTION # # To solve the given differential equation symbolically we use the Maple # command `dsolve', which is in the standard Maple library (not the # DEtools package). # # The general solution is found by the following command; the first # argument is the equation and the second is the variable to be solved # for. # # > dsolve(eq1,y(t)); y(t) = -3 + t + exp(-t) _C1 # # Note the way in which Maple designates arbitrary constants. Often, # but not always, the constant appears after the term that it # multiplies. # # To find the solution of an initial value problem we include the # initial condition in the statement of the problem, enclosing the # differential equation and initial condition in braces. For later # reference we will name the solution `sol'. # > sol := dsolve({eq1,y(0)=0},y(t)); -3 exp(t) + exp(t) t + 3 sol := y(t) = ------------------------ exp(t) # # It is important to understand that `sol' is an equation, not a Maple # expression. In order to calculate values of the solution at # particular values of t, or to plot the solution, or to perform other # operations on it, we must pick off the right hand side of `sol' and # give it a name, such as y1. In the following command `rhs' stands for # `right hand side'. # > y1 := rhs(sol); -3 exp(t) + exp(t) t + 3 y1 := ------------------------ exp(t) # # The last two commands can be combined, if you wish. # > y2 := rhs(dsolve({eq1,y(0)=0},y(t))); -3 exp(t) + exp(t) t + 3 y2 := ------------------------ exp(t) # # Now we can evaluate y1 at a particular value of t, or plot its # graph, using standard Maple commands. # > evalf(subs(t=3,y1)); .1493612051 > plot(y1,t=0..6,y=-2..2,title=`Figure 4`); # Compare this graph with the one in Figure 2. # # The graph in Figure 4 was produced by evaluating the symbolic solution # for a number of t values, and then drawing a curve through the # points generated in this way. The graph in Figure 2 was produced by # evaluating approximate values of y by a numerical process applied # directly to the differential equation, without knowing a symbolic # expression for the solution. The latter process is more general and # is particularly useful for those equations (which are very numerous) # for which analytical solutions cannot be found. #