> restart;
>
Note: You can do your homework for this worksheet within the worksheet or in a new worksheet. As with the previous worksheet, you have to execute all the commands below to see their output and to load the necessary packages DEtools and plots .
First and Second Order Differential Equations, Part I
Maple is very powerful in handling differential equations. Most of the relevant commands are contained in the package DEtools that is loaded with the command
> with(DEtools):
>
Since we are going to do a lot of plotting in this worksheet, we shall load the package plots as well.
> with(plots):
>
Note: If you don't have much experience with Maple, or you never had differential equations in your Calculus courses, you may want to have a look at the worksheet "Differential Equations" (odes.mws) written for Calculus II. You can download the worksheet from the site www.math.uri.edu/Center/workc2.html.
>
Syntax For Differential Equations You Must Know
>
How to enter and solve an ordinary differential equation (ODE) or an initial value problem (IVP) is best illustrated by examples.
>
Example 1. (a) Find a general solution to the ODE:
y'(x) -
= 0
(b) Plot a few solutions.
(c) Solve the IVP:
y'(x)-
= 0, y(1) = 0.
>
The ODE above is an example of a so-called Ricatti equation. With considerable effort you could solve it by hand (see Kreyszig, page 40). Maple can do it for us without any effort at all.
Let's label our equation ODE1 and enter it. Observe the proper syntax. Note that y is always entered as y(x) and not y!
> ODE1:=diff(y(x),x)-x^3*(y(x)-x)^2-(1/x)*y(x)=0;
>
The main command for solving differential equations is dsolve .
Note: It is very important to remember that, as far as Maple is concerned, the output of the command dsolve is neither a function nor an expression. It is an equality at which you can look, but you can't process it any further. To overcome this effect, you have to take the right-hand side of the equality, rhs(%) , and make it into an expression by giving it a name, say, sol1 . Recall that rhs stands for the right-hand side, % for the output of the last executed command.
> dsolve(ODE1,y(x)); sol1:=rhs(%);
>
Maple returns the general solution of the ODE. _C1 stands, of course, for an arbitrary constant. Note that an arbitrary constant is preceeded by an underscore _.
To plot a few members of the general solution, we want to substitute a few values of _C1 into sol1 . To save some typing we use the sequence command, seq, combined with the substitution command subs . Note that the arbitrary constant is entered with the underscore!
> somesol1:=seq(subs(_C1=i,sol1),i=-2..2);
>
We see that the particular solutions that we obtained have vertical asymptotes. Hence, when plotting, we shall restrict the range for y. The option discont=true prevents Maple from printing asymptotes. Under the plot command we enclosed somesol1 in brackets [..] , which makes it an (ordered) list. We assigned the list of colors to the list of solutions.
> plot([somesol1],x=-2..2,y=-10..10,color=[blue,red,magenta,yellow,green],discont=true);
>
We see vertical asymptotes of particular solutions. Many solutions meet at the origin, none cross the x-axes. That is because points where x=0 are singular points of our ODE. The right-hand side is not even defined there!
To solve an IVP you use the syntax:
> dsolve({ODE1,y(1)=0},y(x));
>
As you know, it is not always possible to find a solution to a given ODE in a closed form. In that case, Maple has a powerful numerical solver to solve and plot solutions to IVPs. See odes.mws at www.math.uri.edu/Center/workc2.html for details.
>
Example 2. Consider the family of functions
,
where K is an arbitrary constant.
(a) Find the ODE corresponding to the family.
(b) Plot a few curves of the family in one coordinate system.
To find the ODE for which our family is a general solution, we are going to differentiate implicitly the xy-equation. There is a simple command implicitdiff for this. Let's label our equation:
> Eq1:=x^2-3*y^2=K;
> implicitdiff(Eq1,y(x),x);
>
Note the syntax under
implicitdiff
command: first you enter the equation, or a name of an equation assigned earlier, then you tell Maple which variable is considered a function and which an independent variable. Maple returns a formula for
. Hence, the equation for our family is:
.
We can check using dsolve what is the general solution to the equation.
> dsolve(diff(y(x),x)=x/(3*y(x)),y(x));
>
Often for purposes of plotting or finding orthogonal trajectories, it is more convenient to have a general equation in an implicit form rather than explicit. You can ask Maple for an implicit solution by adding implicit under the dsolve command.
> dsolve(diff(y(x),x)=x/(3*y(x)),y(x),implicit);
>
Clearly, the latter family of curves is exactly the same as our family
, although it is written in a different way.
To plot a few curves of our family, we shall use the implicitplot command. First, let's single out a few curves to be plotted.
> somecurves:=seq(subs(K=i,Eq1),i=-2..2);
Now we shall plot the collection of curves somecurves.
> implicitplot({somecurves},x=-4..4,y=-4..4,color=blue,scaling=constrained);
>
Note: The implicitplot command will not allow you to plot a list of equations, [equations] , but only an unordered set of equations {equations} . Hence, in order to plot two different families in two different colors in one coordinate system, you need to use the display command.
>
>
An Interesting Animation
>
Example 3: F ree Oscillations. If a mass, m, is attached to a spring, with spring modulus k, and allowed to oscillate in the absence of any damping forces, the vertical displacement, y(t), of the mass obeys the following second-order equation
y''(t) +
y(t) = 0 , y(0) =
, y'(0)=
,
where
,
are the initial displacement and the initial velocity, respectively. Assume y(0)=1, y'(0)=1. Let's find y(t) for arbitrary k,m and use Maple's animation facility to illuminate the result.
For simplicity, denote
a
=
. We know that the solution to the ODE looks differently for positive and negative
a
's. Hence, let's assume that
a
>0. (Although, if you assume nothing, Maple will assume
a
>0.)
> assume(a>0);
> ODE2:=diff(y(t),t$2)+a*y(t)=0;
>
The wave next to a variable means that specific assumptions have been made about the variable.
> dsolve({ODE2,y(0)=1,D(y)(0)=1},y(t)); motion:=rhs(%);
>
Note that the initial condition for the velocity is entered as D(y)(0) and not in any other way! "motion" is an expression in terms of t and a . To animate, it is convenient to have a function of a and t . We can accomplish this by use of the command unapply .
> g:=unapply(motion,(a,t));
>
Now, let's animate the solution over the time interval t from 0 to
, and see how the motion depends on
a
.
> animate(g(a,t),t=0..4*Pi,a=(1/9)..4,frames=20,color=magenta,labels=["time","displacement"]);
>
To see the actual animation , click on the plot above. You will see the row of buttons appearing below the toolbar. The buttons look and work much like buttons on your VCR. You press the arrow button to play. Pressing the last button, with an arrow twisted in a circle, followed by pressing the play button, will cause the animation to repeat itself over and over again in a loop. To slow the animation, press the button with the double arrow pointing to the left and so on.
Now, remember what it is that you see. You see the motion of the mass over a fixed time interval [0,4*Pi] for values of a changing from very small, 1/9, to larger and larger up to 4. What do you observe about the frequency and the amplitude of the motion? The answer to this question and its physical meaning is one of your homework problems given in the next section.
>
Homework Problems
>
Problem 1. Consider the following two families of curves:
Family 1:
, where
C
is an arbitrary constant,
Family 2:
, where
K
is an arbitrary constant.
(a) Find the ODE corresponding to each family.
(b) Using your answer in (a), explain why the two families are orthogonal.
(c) Plot a few curves of each family, all in one coordinate system. Make sure to use the scaling=constrained option to see the orthogonality. Use two different colors for the two families to see which curve belongs to which family.
>
>
>
Problem 2. Look carefully at the animation in Example 3.
(a) Assume that k remains constant and m decreases. What happens to the amplitude and the frequency of oscillations? Can you explain it in physical terms?
(b) Assume that m remains constant and k increases. What happens to the amplitude and the frequency of oscillations? Any explanation?
>
>
>
Problem 3. Suppose that you have a spring suspended from a fixed support. A small bucket of sand is attached to the end of the spring and oscillates vertically. As it happens, the bucket has holes in it. Hence, the mass of the sand is gradually decreasing with time. Let's neglect all damping forces and assume that the initial position and velocity of the bucket both are equal to 1. A possible mathematical model for this situation is:
y''(t) +
y(t) = 0 , y(0)=1, y'(0)=1 .
(The coefficient exp(t/5) at y(t) represents the increasing quotient k/m.)
(a) Enter the above IVP and have Maple solve it. Do not be discouraged by a lengthy solution!
(b) Plot the solution over a long enough time interval, say t from 0 to 25. Wait patiently for the plot to appear. It will take a while! What do you observe regarding the amplitude and the frequency of oscillations? Any physical explanation of your observations?
>
>
>
Problem 4. Consider the ODE
.
(a) Find a general solution to the ODE using Maple.
(b) Plot a few curves to have an idea about the geometric appearance of the general solution.
(c) If you didn't have Maple, could you solve the equation by hand? What kind of ODE is it?
>
>
>
>
MTH 362 Maple Worksheets written by B. Kaskosz and L. Pakula, Copyright 2000.
>