MATH 308 Sheet 1 Some syntax trouble spots: multiplication 3*t for 3t powers x∧2 for x2 number π Pi Greek letter π pi sin(x) abs(x) cos(x) sqrt(x) tan(x) ln(x) exp(x) for for for for for for for sin x |x| cos x √ x tan x ln x ex Maple can be used to plot direction fields and solution curves. You must load the DEtools package once on each worksheet: > with(DEtools): Note the colon will suppress any output from Maple, whereas a semicolon will not. dy Example 1. = −y. dx Assign the differential equation the name de for easy handling and to avoid trouble, always type the dependent variable y as y(x). > de:=diff(y(x),x)=-y(x); > DEplot(de,y(x),x=-3..3,y=-3..3); To plot the direction field and solution curves, for example the solutions satisfying y(1) = 2, y(−1) = −1 and y(1) = 1, proceed as follows: > inits:=[ [1,2],[-1,-1],[1,1] ]; Here we’re telling Maple the initial conditions in the appropriate form. Always be sure to enclose the list in square brackets. > DEplot(de,y(x),x=-3..3,inits,y=-3..3); You might need to play around with the x and y plot ranges to get a good plot. If you just want a plot of the solution curves, include the arrows=none option: > DEplot(de,y(x),x=-3..3,inits,y=-3..3,arrows=none); NOTES 1. For good printouts, include the option linecolor=black to make the solution curves black. 2. If your solution curves appear jagged, include the option stepsize=h, where you choose h by trial and error to get a good plot. For instance, try .1, .05, .01 etc. Please note on exam, your solution will lose credit if your solution curves appear jagged. Place the option after the y range. 3. To resize Maple’s plots, click on the graph and drag the corners with the mouse. 4. Use the initial conditions to help you pick the x and y plot ranges. For instance, if y(−3) = −1, use x=-6..0, y=-4..2 as a starting point and play around from there if necessary. 5. The command restart: will clear all values of variables. It’s a good thing to try when things go wrong. 6. To type text in a Maple worksheet, hit the button with the T on it. To restore the Maple prompt, hit the button with the [ > on it. dy Example 2. = sin(y). Plot the direction field using Maple. What happens to the dx solution satisfying 1. y(0) = 1 as x → ∞. 2. y(2) = −2 as x → ∞. 3. y(0) = 7 as x → ∞. Example 3. The population p(t) in thousands of a certain species satisfies the differential dp = 3p − 2p2 . Use Maple to sketch the direction field and use it to answer the equation dt following questions. 1. If the initial population is 2000 individuals (i.e., p(0) = 2), what is the limiting population? 2. If the initial population is 500 individuals, what is the limiting population? 3. Can a population of 3000 individuals ever decline to 500 individuals? Example 4. For a bar magnet, the magnetic field lines satisfy the differential equation dy 3xy = 2 . Plot the direction field. dx 2x − y 2 We have to iterate the algorithm that realizes an Euler’s method to construct approximations to the solution of the initial value problem for first-order differential equation: dy = f (x, y), y(x0 ) = y0 . dx As you know, an Euler’s method can be summarized by the recursive formulas xn+1 := xn + h, yn+1 := yn + f (xn , yn ), n = 0, 1, 2, . . . Lets construct numerical approximations to the initial value problem 1 y dy = 2 − − y2, dx x x y(1) = 1 on the interval 1 < x < 2. To iterate this algorithm, we use the for k from start to finish do..od construction. The following sequence of Maple commands performs ten iterations of this procedure with step h = 0.1 and therefore computes approximate values at the points x = 1, 1.1, 1.2, ...1.9, 2.0. These values are contained in a sequence of points named eseq. > f:=(x,y) -> 1/xˆ2-y/x-yˆ2;inits:=y(1)=1; 1 y − − y2 2 x x inits := y(1) = 1 f := (x, y) → Notice, that the function above is an arrow-defined function an not a Maple expression. > x:=1:y:=1:h:=0.1: # initialize x and y an the step size > eseq:=[x,y]; # input the initial conditions into eseq eseq := [1, 1] > for i from 1 to 10 do y:=evalf(y+h*f(x,y)): # compute the new value of y x:=x+h: # update the new value of x eseq:=eseq,[x,y]: # ad the new point od: > x:=’x’:y:=’y’:h:=’h’: To display the contest of the solution values in eseq, type the variable name. > eseq; [1, 1], [1.1, .9], [1.2, .8198264463], [1.3, .7537404800], [1.4, .6981195696], [1.5, .6505372009], [1.6, .6092926336], [1.7, .5731505927], [1.8, .5411877679], [1.9, .5126975583], [2.0, .4871284287] To plot the approximation between x = 1 and x = 2, we could use plot([eseq]);. 1.0 0.9 0.8 0.7 0.6 0.5 1.0 1.2 1.4 1.6 1.8 2.0 1. Use Euler’s method to find approximations to the solution of the initial value problem y ′ = 1 − sin y, y(0) = 0, taking 10 steps. 2. Use Euler’s method to find approximations to the solution of the initial value problem y ′ = 1 + x2 , taking 10 steps. y(0) = 0,