Solving Differential Equations
Mathematica's differential equation solvers DSolve and NDSolve
can handle a huge number of ordinary and partial differential equations analytically or
numerically. For more information about any of the functions described in this section,
please visit the Wolfram Library Archive.
DSolve
DSolve finds symbolic solutions for an ever increasing number of differential
equations. These solutions are easier to verify, use, and recalculate than numeric solutions,
and they provide a better understanding of the problems being studied.
The following are some implementation notes about the analytical differential equation
solver DSolve.
DSolve can solve linear ordinary differential equations of any order
with constant coefficients. It can also solve many linear equations up to second order
with nonconstant coefficients.
DSolve includes general procedures that handle a large fraction of the
nonlinear ordinary differential equations whose solutions are given in standard reference
books.
DSolve can find general solutions for linear and weakly nonlinear
partial differential equations. Truly nonlinear partial differential equations usually
have no general solutions.
Examples
This example is a simple boundary value problem. Note that Mathematica can handle
higher-order differential equations without requiring you to manually transform them
into a system of first-order equations.
![[Graphics:../Images/index_gr_103.gif]](../Images/index_gr_103.gif)
![[Graphics:../Images/index_gr_104.gif]](../Images/index_gr_104.gif)
The same syntax works for partial differential equations. Mathematica automatically detects partial differential equations and selects the algorithms accordingly.
![[Graphics:../Images/index_gr_105.gif]](../Images/index_gr_105.gif)
![[Graphics:../Images/index_gr_106.gif]](../Images/index_gr_106.gif)
NDSolve
NDSolve finds numerical solutions to differential equations. It automatically
selects the optimal algorithm to use or lets you select it if you know it in advance.
Mathematica alone uses interpolation functions instead of simple lists of numbers
to represent numerical solutions to differential equations, making it easy to reuse the
results of Mathematica's NDSolve. All results can be used like any other
function, namely, integrated, differentiated, or included in more-complex calculations.
The following are some implementation notes about NDSolve.
By default or with Method->Automatic, NDSolve switches
between a nonstiff Adams method and a stiff Gear method.
NDSolve is based on LSODE.
The implicit Adams method is used with order between 1 and 12.
The Gear backward difference formula method with order between 1 and 5 is used.
The Fehlberg order 4-5 Runge-Kutta method is applied to nonstiff equations.
For linear boundary value problems, NDSolve employs the Gel'fand-Lokutsiyevskii
chasing method.
For 1+1-dimensional PDEs, the method of lines is used.
The differential equations in NDSolve can involve complex numbers.
Mathematica's adaptive algorithms and arbitrary-precision control guarantee
accurate results without roundoff errors or spurious solutions due to numerical errors.
Example: Solving the Van der Pol Equation with Mathematica and Plotting the Result
The result can be obtained in Mathematica with the following single line of code.
![[Graphics:../Images/index_gr_107.gif]](../Images/index_gr_107.gif)
![[Graphics:../Images/index_gr_108.gif]](../Images/index_gr_108.gif)
The resulting InterpolationFunction can be used like any other Mathematica
function, namely, integrated, differentiated, plotted, transformed, and so on.
![[Graphics:../Images/index_gr_109.gif]](../Images/index_gr_109.gif)
You can also instantly verify the result by differentiating
.
![[Graphics:../Images/index_gr_113.gif]](../Images/index_gr_113.gif)
![[Graphics:../Images/index_gr_116.gif]](../Images/index_gr_116.gif)
Or you can calculate and plot the integral over the solution in one step.
![[Graphics:../Images/index_gr_119.gif]](../Images/index_gr_119.gif)
Partial Differential Equations
Mathematica provides you with the easiest way to solve a large number of
partial differential equations numerically or symbolically.
![[Graphics:../Images/index_gr_122.gif]](../Images/index_gr_122.gif)
![[Graphics:../Images/index_gr_123.gif]](../Images/index_gr_123.gif)
![[Graphics:../Images/index_gr_124.gif]](../Images/index_gr_124.gif)
![[Graphics:../Images/index_gr_125.gif]](../Images/index_gr_125.gif)
Numerical solutions work exactly the same way. For example, we can solve
the wave equation numerically, plot the solution, and make a contour chart
of its derivative with respect to t.
res = NDSolve[{D[y[x, t], t, t] == D[y[x, t], x, x], y[x, 0] == Exp[-x^2],
Derivative[0, 1][y][x, 0] == 0, y[-5, t] == y[5, t]}, y, {x, -5, 5},
{t, 0, 5}]
![[Graphics:../Images/index_gr_126.gif]](../Images/index_gr_126.gif)
Plot3D[Evaluate[D[y[x, t],t] /. First[res]], {x, -5, 5}, {t, 0, 5}, PlotPoints->30]
![[Graphics:../Images/index_gr_129.gif]](../Images/index_gr_129.gif)
|