




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A maple session for getting started with first order differential equations. It covers loading the 'detools' library, defining a differential equation, creating direction fields using the 'deplot' command, and solving differential equations analytically using the 'dsolve' command.
Typology: Study notes
1 / 8
This page cannot be seen from the preview
Don't miss anything!
September 2003
In this Maple session, we see some of the basic tools for working with differential equations in Maple. We will only deal with first order equations here.
First, we need to load the "DEtools" library: > with(DEtools): Let's define a differential equation. As an example, we consider y' = y(4-y). This is a first order ordinary differential equation. (It is Problem 11 of Section 1.1 in the text.)
The following command defines a variable called "eq" that holds the differential equation:
> eq := diff(y(t),t) = y(t)(4-y(t));*
eq := = โ
t
y( ) t y( ) t ( 4 โy( ) t )
A few points:
Two useful commands are "DEplot" and "dsolve".
Let's create a direction field for this equation. One Maple command that does this is called "DEplot". In the first example given here, the first argument is the differential equation, the second is the unknown function in the differential equation, the third is the range of the independent variable to show in the plot, and the fourth is the range of the dependent variable.
> DEplot(eq,y(t),t=-1..1,y=-1..5);
Here is the same example, with some additional arguments included. For example, the "dirgrid" option lets you decide how many arrows to include, and "color=black" makes the arrows black. > DEplot(eq,y(t),t=-1..1,y=-1..5,title=Direction Field
,color=black,dirgrid=[25,25]);
Notice that a quick glance at the diection field let's us predict how the solutions will behave. Before proceeding, print a copy of the above direction field, and sketch the solution for which y(0)=1. Be sure to consider negative t as well as positive. Also sketch the equilibrium solutions.
How to print the direction field: (1) In the menu bar, select Options -> Plot Display -> Window When you select this option, subsequent plots will appear in a separate window, rather than in Maple session. (2) Move the cursor back to the previous DEplot command and hit enter. This will execute the command again, and now it will appear in a separate window. (3) Click on the printer icon, or use the menu bar File -> Print
whole point of a direction field!
Important Note: The solution curves plotted by the DEplot command have been computed numerically , using an algorithm similar to Euler's Method. They are generally good approximations, but they are not exact, and they may occasionally be very bad approximations.
The command "dsolve" can solve some differential equations analytically. Let's start out with a simple example: y' = -y. (If you haven't done so before, solve this by hand before continuing. It is both linear and separable.)
First, we'll define the equation, and save it in a Maple variable called "eq2": > eq2 := diff(y(t),t) = -y(t);
eq2 := = โ
t
y( ) t โ y( ) t
Now we'll use "dsolve" to find the general solution. The first argument of "dsolve" is the equation, and the second is the function to solve for: > dsolve(eq2,y(t));
y( ) t = _C1 e
( โ t )
This should look familiar! Notice that Maple has called the arbitrary constant "_C1". This is a common Maple convention; when it creates a constant, it typically puts an underscore in the beginning of the name.
We can also use "dsolve" to solve an initial value problem. For example, suppose we have the initial condition y(0)=2. We specify this in the command by combining the differential equation with the initial condition in "curly brackets": > dsolve({eq2,y(0)=2},y(t));
y( ) t = 2 e
( โ t )
Look at that example carefully. The first argument of dsolve is {eq2,y(0)=2}. In Maple, curly brackets are commonly used to create lists of things. In this case, we make a list of the equation and the initial condition, and pass this to "dsolve" as its first argument. The second argument, y(t), stays the same.
How do we plot this solution? Unfortunately, the solution given above is not in a format that is easily plotted by the "plot" command. The plot command plots expressions, but the above solution is actually an equation (it has an equals sign sitting the middle). The expression that we want, namely 2*exp(-t), is the right-hand-side of the equation. Fortunately, there is a command in Maple that lets us take the right-hand-side from an equation. The function is called "rhs".
So here is one way to plot the solution above. First, save the solution in a variable, say "sol2" (because it solves eq2): > sol2 := dsolve({eq2,y(0)=2},y(t));
sol2 :=y( ) t = 2 e
( โ t )
Now take out the right-hand-side, and save it in a new variable called rhsSol2: > rhsSol2 := rhs(sol2);
rhsSol2 := 2 e
( โ t )
Now plot it: > plot(rhsSol2,t=-1..2);
You can combine several of those steps: > sol2 := rhs(dsolve({eq2,y(0)=2},y(t)));
sol2 := 2 e
( โ t )
> plot(sol2,t=-1..2);
Let's try another example. Recall that "eq" is still defined: > eq;
> plot(sol1c,t=-1..1);
What happened?
Let's force the plot command to use a smaller vertical range. > plot(sol1c,t=-4..4,y=-3..5);
It appears that the solution has a vertical asymptote. If you look at the solution found above, you'll see that this is the case. In fact, we can find that value where it occurs by finding where the denominator is zero. In the following, we use the "denom" command to get the denominator, and then find the root using the "solve" command. > den := denom(sol1c);
den :=โ 1 + 9 e
( โ 4 t )
> r := solve(den=0,t);
r :=
ln 9( )
> evalf(r);
Can Maple solve any first order differential equation? Unfortunately, no. Here is a simple example: > eq3 := diff(y(t),t) = sin(y(t))+cos(t);
eq3 := = โ
t
y( ) t sin( y( ) t )+cos( ) t
> dsolve(eq3,y(t)); The function returns nothing; Maple can not solve this equation.