Math 221 Differential Equations Maple Page
 Math 221 Maple V Page The math department has a small collection of Maple worksheets (as Maple files are called) that you can experiment with. What follows are my own results of experimenting with Maple code. Basic Maple etiquette:Every line (or rather, complete expression) must end with a colon (:) or semicolon (;) . A colon will supress the output of the line, a semicolon will print the output of the line. This bit of Maple code: with(DEtools): dfieldplot([diff(x(t),t)=1, diff(y(t),t)=1+x(t)*(y(t)*y(t)-3*x(t)-2)],[x(t),y(t)],t=-2..2,x=1..2,y=2..3); will draw a direction field for the differential equation [dy/dt] = 1+t(y2-3t-2) This bit of Maple code: with(DEtools): DEplot([diff(x(t),t)=1,diff(y(t),t)=1+x(t)*(y(t)*y(t)-3*x(t)-2)], [x(t),y(t)],t=-2..2,[[x(0)=1,y(0)=2],[x(0)=1,y(0)=2.1],[x(0)=1,y(0)=2.15], [x(0)=1,y(0)=2.17], [x(0)=1,y(0)=2.1695]],x=1..2,y=2..3,stepsize=.005); will draw a bunch of solutions for the equation. From these examples it ought to be fairly straightforward for you to build examples of your own; just replace "diff(y(t),t)=1+x(t)*(y(t)*y(t)-3*x(t)-2)" with "diff(y(t),t)= a function of your own". Note that "x(t)" is how these examples need you to write "t". Here is another example, to help separate out the pieces for changes: with(DEtools): DEplot([diff(x(t),t)=1, diff(y(t),t)=32-1.6*y(t) ], [x(t),y(t)], t=0..10, [ [x(0)=0,y(0)=0], [x(0)=0,y(0)=10], [x(0)=0,y(0)=20], [x(0)=0,y(0)=25] ], x=0..10, y=0..25, linecolor=[blue,green,black,violet], stepsize=.005); This illustrates one of your homework problems. Cutting and pasting (and then editing) this code into the Maple V front-end available online can give you a quick and dirty way to make some plots of slope fields and (approximate) solutions. The command "dsolve" can be used to solve (symbolically) differential equations: for example, you can try dsolve(diff(y(t),t)-y(t)^2); This will return all solutions to the differential equation [dy/dt] - y2 = 0. You can get a good sense of the fine line between equations `easy' to solve and those that aren't by comparing Maple's answers to dsolve(diff(y(t),t)-t*y(t)^2); and dsolve(diff(y(t),t)-t*y(t)^2-1); (i.e., to [dy/dt] = ty2 and [dy/dt] = ty2 + 1). And while it could handle [dy/dt] = ty2 + t just fine, it couldn't do anything with [dy/dt] = ty2 + t+ 1. To numerically solve a differential equation, using (forward) Euler's method, the following bit of code will do the job: with(DEtools): deqn := diff(y(t), t) = y(t): init1 := y(0)=1: ans:= dsolve({deqn, init1}, {y(t)}, numeric, method=classical[foreuler], stepsize=.1): ans(1.0),ans(2.0),ans(3.0),ans(4.0),ans(5.0); You can, of course, insert your own functions into `deqn', adjust the stepsize, initial condition, and points you want to evaluate your approximate solution at! Here is some code to explore the solutions to spring-mass problems: with(DEtools): m:=1: gam:= 0.0: k:= 9: om:=3.3: f(t):=cos(om*t): de := m*diff(y(t),t\$2) +gam*diff(y(t),t) + k*y(t) = f(t); DEplot(de,y(t),t=0...20,[[y(0)=0,D(y)(0)=0]],stepsize=.01); You can, as usual, change the values of m, gam, k, and om, as well as the initial conditions, to generate examples of the various phenomena that we explored in class. Here is some code for exploring systems of linear first order equations: with(DEtools): a:=2: b:=3: c:=-3: d:=4: charp:= k^2-(a+d)*k+(a*d-b8c); roots_:=solve(charp,k); DEplot([diff(x(t),t)=a*x(t)+b*y(t), diff(y(t),t)=c*x(t)+d*y(t)], [x(t),y(t)],t=-10..10,color=black,linecolor=blue, [[x(0)=2,y(0)=0],[x(0)=-1,y(0)=-1],[x(0)=0,y(0)=1], [x(0)=0,y(0)=3],[x(0)=0,y(0)=-1],[x(0)=0,y(0)=-3]], x=-5..5,y=-5..5,stepsize=.01); As you can probably tell, a and b are the coefficients in the first equation, while c and d belong to the second. This code will tell you what the associated matrix is, compute its characteristic polynomial and eigenvalues, and draw the direction field and a few solution curves for the equation (i.e., draw a phase portrait). So you can use this to see the effect on the phase portrait of changes to your initial matrix. A much more jazzed up version of this Maple routine can be found here; it will determine (for a 2-by-2 system) where the eigenvectors are, plot all of the straight-line solutions, and attempt to do a good job of picking other representative solutions. It's pretty cludgy (because I kept needing to avoid dividing by 0), so if you know of, or figure out, or stumble across a slicker way to do it, please let me know!