Working with DSolve: A User's Guide

Introduction

The aim of these tutorials is to provide a self-contained working guide for solving different types of problems with DSolve.

The first step in using DSolve is to set up the problem correctly. The next step is to use DSolve to get an expression for the solution. Once the solution has been found, it can be verified using symbolic or numerical techniques, or it can be plotted using a Wolfram System function such as Plot, Plot3D, or ContourPlot. Plots often reveal information about the solution that might not be evident from its closed-form expression.

If no boundary conditions are specified for a problem, the output from DSolve is some form of a general solution containing arbitrary parameters. The GeneratedParameters option can be used to label these arbitrary parameters.

In many applications, differential equations contain symbolic parameters, such as the rate of growth in the logistic equation. A differential equation can also contain inexact quantities, such as machine numbers arising from previous calculations. Both symbolic parameters and inexact quantities are allowed by DSolve, but it is good to be aware of their presence and interpret the solution correctly.

When DSolve makes any assumptions or encounters difficulty during a calculation, it issues a warning message outlining the problem. These messages can usually be ignored, but sometimes they point to serious limitations in the answer given for the problem.

It is helpful to analyze the statement of the problem for possible ambiguitiesin other words, to make sure that the problem is well posedso that meaningful answers can be obtained from DSolve.

Setting Up the Problem

The first argument given to DSolve is the differential equation, the second argument is the unknown function, and the last argument identifies the independent variable.

Here is the input for solving for a first-order linear ODE using DSolve. The variable sol identifies the solution for use in further work:

The output of DSolve is a list of solutions for the differential equation. The extra list is required since some equations have multiple solutions. Here, since the equation is of order 1 and is linear, there is only one solution: y[x]->+-5 x C[1]. The solution has an undetermined constant C[1] because no initial condition was specified. The solution can be extracted from the list of solutions using a part specification.

This extracts the solution:

This form of the solution is useful for finding itself, but not for finding derivatives of or the value of at a point.

This shows the value of given by the solution:
The solution does not apply to or because the solution is a rule for only:

If the solution will be used in further work, it is best to specify the unknown function using rather than . This gives the solution using pure functions of the type Function[x,expr].

Here, the unknown function is specified as . The solution is a pure function:

When the solution is in the form of pure functions, expressions can be found for derivatives of and for the values of at specific points.

This gives expressions for , , and :

When a problem has multiple solutions, you can pick out individual solutions from the solution list or you can work directly with the list.

This solves a nonlinear first-order equation. There are two solutions:
The solutions can be extracted using part specifications:
This returns a list of both expressions:

To solve a system of equations, the first argument to DSolve must be a list of the equations and the second argument must be a list of the unknown functions.

Here is an example of a system of first-order linear equations with three unknowns. Because this system is linear, there is only one solution:

Each solution to the system is a list of replacement rules for the unknown functions. The expressions for the unknown functions can be extracted as in previous examples.

This gives a list of the expressions for the unknown functions. Simplify is used to return the expressions in a compact form:

If initial conditions are prescribed for the problem, some or all of the undetermined constants can be eliminated.

Here the value of the unknown function and its derivative are both prescribed at the initial point:
If only the initial value is specified, then the solution still contains an arbitrary constant:

For a partial differential equation, the third argument to DSolve is a list of the independent variables for the equation.

This solves a PDE with independent variables and . C[1] represents an arbitrary function of y+Cos[y[x]]:

A differential-algebraic equation is specified in the same way as a system of ordinary differential equations.

Here is an example of a DAE with an initial condition:

Note that it is not always possible to give the solutions for a problem in explicit form. In this case, the solution is given using an unevaluated Solve object or using InverseFunction.

The solution to this equation is not available explicitly. The output represents an implicit solution:
The solution can be extracted as usual with a part specification:
The solutions to this equation are given as InverseFunction objects:
Each solution can be rewritten as an implicit equation by eliminating the InverseFunction object as follows:

Verification of the Solution

The solution given by DSolve can be verified using various methods. The easiest method involves substituting the solution back into the equation. If the result is True, the solution is valid.

In this simple example, the solution is verified by substitution. Note that the first argument to DSolve is assigned to eqn for convenience in later work:
In this example, the equation and an initial condition are verified by substitution:

Sometimes the result of the substitution is more complicated than True or False. Such examples can be verified by using Simplify to simplify the result of the substitution. If the simplified result is True, the solution is valid.

Here is the general solution for a second-order inhomogeneous equation:
This substitutes the solution back into the equation:
The solution can be verified using Simplify:
Here is a linear PDE whose solution can be verified using Simplify:

If the equation involves special functions, it may be necessary to use FullSimplify to verify the solution.

Here is an example of this type involving Bessel's functions:

If the solution is large or if Simplify and FullSimplify do not succeed in verifying the solution, a numerical check can be made by using RandomReal or RandomComplex to generate values for all the variables and parameters in the problem. It is advisable in such cases to repeat the check with several sets of random values.

Here is an example where numerical verification is useful:

Although numerical checks cannot verify a solution with certainty, more rigorous checks can be made by using higher precision or by allowing the variables to take complex values.

This verifies the previous solution with higher precision:
This uses complex random values to verify the previous solution:

The previous methods are of use only when the solution is available in explicit form. The final example shows how to verify the solution of a first-order ODE when it is given in implicit form.

This solves a first-order ODE:
This verifies the solution by simplifying its derivative:

Plotting the Solution

A plot of the solution given by DSolve can give useful information about the nature of the solution, for instance, whether it is oscillatory in nature. It can also serve as a means of solution verification if the shape of the graph is known from theory or from plotting the vector field associated with the differential equation. A few examples that use different Wolfram Language graphics functions follow.

Here is the general solution to a linear first-order equation:
The solution can be plotted for specific values of the constant C[1] using Plot. The use of Evaluate reduces the time taken by Plot and can also help in cases where the solution has discontinuities:
Here is the plot for a linear second-order ODE with initial values prescribed at 0:
This nonlinear equation has two solutions that can be plotted on the same graph:
The solution to this Abel ODE is given in implicit form:
A contour plot can be used to study the nature of the solution. Each contour line corresponds to a solution to the ODE for a fixed value of C[1]:
Here is the plot of the solutions to a system of two linear ODEs. The WorkingPrecision option in Plot is required because the solution is fairly complicated:
The ParametricPlot function can be used to trace the solution curve {x[t],y[t]} in the plane:
Here is the plot for the solution to a DAE:
Here is the general solution to a linear PDE:
Here is a plot of the solution surface for a particular choice of the arbitrary function C[1]:

Generated Parameters

The general solution to a differential equation contains undetermined coefficients that are labeled C[1], C[2], and so on.

This example has one undetermined parameter, C[1]:

To change the name of the undetermined parameter, use the GeneratedParameters option.

This changes the name of the undetermined coefficient to P[1]:

The parameter C should be thought of as a pure function that acts on a set of indices to generate different constants C[i].

This shows the behavior of C:

Internally, the use of a pure function allows DSolve to increment the argument i in C[i] correctly for higher-order ODEs and systems of ODEs.

GeneratedParameters can be specified using a pure function:

Using a pure function is particularly useful if you want to begin indexing the parameters at any value other than 1 (the default).

This uses a pure function to label the parameters in the previous example const[2] and const[3]:

It is sometimes useful to display the solution using subscripts or other styles for the parameter indices.

Here, the parameters are named using subscripted variables:

Finally, with Module variables, you can get names for the parameters that are unique across different invocations of DSolve.

Here the same DSolve call generates different parameter names:

Symbolic Parameters and Inexact Quantities

The differential equations that arise in practice are of two types.

Here is an example of the first type:
Here is an example of the second type. This equation has a symbolic parameter :

DSolve is equipped to deal with both types of equations. It is extremely useful to have the solution available for all possible values of the parameters in the second type of equation.

Here is a plot of the previous solution for different values of the parameter :

It should be noted that the presence of symbolic parameters can lead to fairly complicated output.

This is seen in the following example (equation 2.14, page 401 of [K59]):

However, for some special values of the parameters, the solution might be significantly simpler.

For these values of and , the solution is much simpler:

Occasionally, a solution is valid for most, but not all, values of the parameters.

Since the input in this example is not valid at , the solution has the same limitation:
Of course, there is a simple remedy in this case: setting :

In summary, the ability to solve differential equations with symbolic parameters is a powerful and essential feature of any symbolic solver such as DSolve. However, the following points should be noted.

Numerical quantities in the Wolfram Language can be of three types: infinite precision, machine precision, or arbitrary precision. The first type of number is referred to as "exact", while the remaining two types represent incomplete information and are therefore called "inexact".

Here is a simple example showing all three kinds of numbers:

Since DSolve is a symbolic solver, the algorithms used by it are primarily based on the assumption of exact input. However, equations that contain inexact quantities are handled by DSolve in the usual way.

These equations contain the inexact number 3. and 3.`40, respectively:

Inexact input could arise, for example, when the coefficients in the equations are derived from a previous calculation and are known only approximately. In such cases, it might not be practical to convert the equations to exact form, as this could slow down the calculation significantly.

Here is a system of linear ODEs that all have exact coefficients. Note that even with a fairly small value of , the calculation takes a long time to finish:
This verifies the solution. Since the solution is complicated, a numerical verification method is used:
If a single inexact quantity is introduced (in the function ), the solution is returned more quickly:

Thus, it is often desirable to continue working with inexact quantities even within a symbolic function such as DSolve. However, it should be noted that the solution obtained in such cases could have a certain amount of numerical error and should be checked carefully. It is therefore recommended that if the problem size is not too large (for instance, if there are fewer than five equations), the input should be converted to exact form using the Rationalize function.

This equation contains inexact quantities:
Here the equation is converted to exact form before being solved:

Is the Problem Well-Posed?

DSolve returns a general solution for a problem if no initial or boundary conditions are specified.

The general solution to this equation is returned:

However, if initial or boundary conditions are specified, the output from DSolve must satisfy both the underlying differential equation as well as the given conditions.

Here is an example with a boundary condition:

In such cases, it is useful to check whether DSolve has been asked a reasonable questionin other words, to check whether the problem is well-posed. An initial or boundary value problem is said to be well-posed if a solution for it is guaranteed to exist in some well-known class of functions (for example, analytic functions), if the solution is unique, and if the solution depends continuously on the data. Given an ODE of order (or a system of first-order equations) and initial conditions, there are standard existence and uniqueness theorems that show that the problem is well-posed under a specified set of conditions. The right-hand side of the first-order linear ODE in the previous example is a polynomial in and hence infinitely differentiable. This is sufficient to apply Picard's existence and uniqueness theorem, which only requires that the right-hand side be Lipschitz-continuous.

Most problems that arise in practice are well-posed since they are derived from sound theoretical principles. However, as a note of caution, the following are examples where DSolve might have difficulty finding a satisfactory solution to the problem.

Here is the solution to a first-order ODE in which the right-hand side fails to satisfy the Lipschitz condition around 0:
The general solution has two branches:
This initial value problem is well-posed in a region around the initial condition and hence DSolve succeeds in picking out the correct branch for the given initial condition:
Here is a second-order ODE. The boundary conditions do not allow any solution to this problem:
In this example, DSolve returns a pair of solutions. As the table shows, the first solution is only valid for values of x greater than or equal to 2:

Finally, it is possible that a problem has a solution, but that DSolve fails to find it because the general solution is in implicit form or involves higher transcendental functions.

In this example, a solution is available only after inverting the roles of the dependent and independent variables:

This concludes the discussion of the basic principles for effectively working with DSolve. See the list of "references" that were found to be useful either during the development of DSolve or during the preparation of this documentation.