Download Solving Differential Equations with Maple: A Comprehensive Guide and more Study notes Mathematics in PDF only on Docsity!
dsolve
The basic Maple command for solving differential equations is "dsolve ". The
basic syntax of dsolve is the usual
dsolve("what", "how");
syntax of most basic Maple commands. "What" refers to the differential equation (or
system of differential equations) together with any initial conditions there might be
-- if there is more than just one equation with no conditions, this must be enclosed in
braces {}. The "How" part, like most solve routines in Maple, indicates the name of
the variable or function to be solved for.
It is useful to give names to all of the equations and initial conditions you are going
to use in dsolve^ -- it makes the statements easier to read and can often save some
typing. For example:
> eq:=diff(y(x),x)=xy(x);*
eq := = โ
x y( x ) x y( x )
> init:=y(2)=1;
init :=y 2( )= 1
Now, eq is the name of the differential equation we will solve, and init is the
name of the initial condition. It is important that we use y(x) rather than just y --
this indicates to Maple that we are thinking of y as the dependent variable and x as
the independent one. To solve the equation WITHOUT the initial condition (i.e., to
find the general solution), we
> dsolve(eq,y(x));
y( x ) = e (^1 /^2 x )
2 _C
Notice the _C1 -- that is Maple's way of producing an "arbitrary constant". To solve
the initial-value problem, we must group the equation and initial condition together
in braces:
> dsolve({eq,init},y(x));
y( x ) =
e (^1 /^2 x )
2
e^2
This last output is an equation -- if you wish to assign the output to a name, so that
you can use it for further work (or to plot it, etc..) it is possible to use the "rhs "
(right-hand side) command (and the double quote, which refers to the last previous
output):
> ans:=rhs(");
ans := e (^1 /^2 x )
2
e^2
Sometime Maple will give the answer in an "implicit" form -- an equation that
relates the dependent and independent variables instead of just an expression for the
independent variable:
> dsolve(diff(y(x),x)=y(x)^2, y(x));
=
y( x ) โ x + _C
But it is clear that one can solve easily for y(x) -- to force Maple to do this, use the "
explicit " option in dsolve :
> dsolve(diff(y(x),x)=y(x)^2, y(x), explicit);
y( x ) =โ
x โ _C
inits :=y 1( )= 2 , D( y )( 1 )= 4 > dsolve({eqn2,inits},y(x));
y( x ) =
( e x^ ) + โ +
2 6
3 (^ e^ )
(^3) 6 ( e ) (^2) e ( โ 2 x ) e x (^) 3 ( e ) (^2 48) e
e x
Sometimes these things get somewhat complicated!
2. Systems of differential equations : In many applications, systems of differential
equations arise. The syntax for these is the same as for initial-value problems (even
when no initial values are specified) --- braces around the problem are required,
AND braces around the list of functions to be solved for. We do one example of an
initial value problem for a system of two first-order equations:
> eqns:=diff(y(x),x)+diff(z(x),x)=x, diff(y(x),x)-2diff(z(x),x)=x^2;*
eqns := + = ,
x y( x )
x z( x ) x โ =
x y( x ) 2
x z( x ) x^2
> inits:= y(0)=1, z(0)=2;
inits :=y 0( )= 1 , z 0( )= 2 > dsolve({eqns,inits},{y(x),z(x)});
{ y( x )= 1 + + , }
3 x
9 x
(^3) z( x )= 2 + 1 โ 6 x
9 x
3
3. Numerical solutions : Very often, it is impossible to obtain the solution to a
differential equation in closed form. In this case, one must resort to a numerical
approximation method. Maple knows a lot of these -- to invoke them, use the "
numeric " option of dsolve , as follows:
> eqn:=diff(y(x),x)+exp(y(x))x^3=2sin(x); init:=y(0)=2;**
eqn := + =
x y( x ) e y(^ x^ ) x^3 2 sin( x )
init :=y 0( )= 2 > F:=dsolve({eqn,init},y(x),numeric);
F := proc ( rkf45_x ) ... end
Your output for the preceeding statement might be slightly different. The output
means that Maple has defined a function called F, that will output the value of y(x)
corresponding to a given (numerical) value of x. For example:
> F(2);
[ x = 2 , y( x )=-.7815970926289340]
It is often useful to plot the numerically-obtained solution of a differential equation.
To do this, you need to apply the Maple command odeplot to the result (F in this
case) of the dsolve(....,numeric) statement. The odeplot command is in
the plots library and so must be loaded using the statement:
> with(plots,odeplot);
[ odeplot ]
To plot the solution, use the following syntax:
> odeplot(F,[x,y(x)],-2..2);
-2 -1 1 2
2
1
0 -0.
In this statement, the "F" is the function that resulted from dsolve(...numeric)
. The second argument indicates to Maple which variables should be on which axis
(sometimes it is useful to plot x versus the derivative of y(x) or y(x) versus the
derivative of y(x)). The final axis gives the domain of the independent variable (x in
this case) over which the plot should be made.
y( x )=Heaviside( x โ 1 ) e (^ โ^ x^ +^1 )
The Dirac and Heaviside functions are the Dirac delta and unit step functions,
respectively (see Chapter 4 of the Math 241 textbook). For more information about
Laplace transforms in Maple, see the section on the laplace command.
Errors :
The most common error one makes when using dsolve is to use the dependent
variable (the "y" above) without specifying the dependence on the independent
variable (in other words, using the y without writing y(x) ). Unexpected results
often happen when you do this.
The other kinds of errors are like the ones that go wrong whenever you use a solving
or plotting routine -- e.g., the variables being solved for have already been assigned
values (that may have been forgotten), etc..