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:

>   restart:

>   eq:=diff(y(x),x)=x*y(x);

eq := diff(y(x),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) = _C1*exp(1/2*x^2)


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) = 1/exp(2)*exp(1/2*x^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 percent sign, which refers to the last previous output):

>   ans:=rhs(%);

ans := 1/exp(2)*exp(1/2*x^2)

More advanced uses of dsolve:

There are four additional ways to use dsolve for situations other than single first-order differential equations and initial-value problems.

1.
Equations of higher order: Second (and higher) order equations can be solved with dsolve. To do this, recall that higher derivatives of a function are taken as follows in Maple (this is the third derivative of f(x)):

>   diff(f(x),x$3);

diff(f(x),`$`(x,3))

So, we can set up a second-order equation as follows:

>   eqn2:=diff(y(x),x$2)+3*diff(y(x),x)+2*y(x)=exp(x);

eqn2 := diff(y(x),`$`(x,2))+3*diff(y(x),x)+2*y(x) = exp(x)

The general solution of this equation is:

>   dsolve(eqn2,y(x));

y(x) = 1/6*exp(x)-exp(-2*x)*_C1+exp(-x)*_C2

Notice that there are two constants, _C1 and _C2 (as to be expected) in the solution. The appropriate initial-value problem requires two initial conditions -- one on the value of y at some value of x, and the other on the value of the derivative at the point. For this problem, we will specify value of y at x=1:

>   inits:=y(1)=2, D(y)(1)=4;

inits := y(1) = 2, D(y)(1) = 4

>   dsolve({eqn2,inits},y(x));

y(x) = 1/6*exp(x)-exp(-2*x)*(-1/3*exp(3)+6*exp(2))+exp(-x)*(-1/2*exp(2)+8*exp(1))


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)-2*diff(z(x),x)=x^2;

eqns := diff(y(x),x)+diff(z(x),x) = x, diff(y(x),x)-2*diff(z(x),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/9*x^3+1/3*x^2+1, z(x) = -1/9*x^3+1/6*x^2+2}


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=2*sin(x); init:=y(0)=2;

eqn := diff(y(x),x)+exp(y(x))*x^3 = 2*sin(x)

init := y(0) = 2

>   F:=dsolve({eqn,init},y(x),numeric);

F := proc (x_rkf45) local res, solnproc, outpoint, ndsol, i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; _EnvDSNumericSaveDigits := Digits; Digits := 14; if _EnvInFsolve = ...


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) = -.781597182233125576]

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,color=blue,thickness=2);

[Maple Plot]


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 argument gives the domain of the independent variable (x in this case) over which the plot should be made.


The most important things to notice are:
(a) You must assign the result of
 dsolve(......,numeric) to a NAME.

 (b) You must use the odeplot function from the plots library to plot the result

 of dsolve(......,numeric). The syntax is as above, and you can see

some more examples in Maple help.

4. You can also use
dsolve to get power series solutions of differential equations.  It is usually best to specify an initial-value problem to do this. The order to which the series is computed is determined by the system variable Order (just as for the taylor command). For example, to solve the initial value problem y'+x*y=0, y(0)=1 by series, you enter:

>   dsolve({diff(y(x),x)+x*y(x)=0, y(0)=1},y(x), series);

y(x) = series(1-1/2*x^2+1/8*x^4+O(x^6),x,6)


If you want more terms:

>   Order:=14: dsolve({diff(y(x),x)+x*y(x)=0, y(0)=1},y(x), series);

y(x) = series(1-1/2*x^2+1/8*x^4-1/48*x^6+1/384*x^8-1/3840*x^10+1/46080*x^12+O(x^14),x,14)


The result of this operation is a Maple "series" (with the "big-O" term) -- see the discussion of this in the  
taylor section of this manual for how to deal with the big O.

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..