How to | Plot the Results of NDSolve

NDSolve solves a differential equation numerically. It returns solutions in a form that can be readily used in many different ways. One typical use would be to produce a plot of the solution.

As an example, take the equation with the initial conditions and :

In NDSolve, make the equation the first argument, the function to solve for, , the second argument, and the range for the independent variable the third argument:

This plots the solution:

It is common to plot the solution along with its derivative (or more than one dependent variable). To see them in different colors use an Evaluate around what you want to be plotted:

For systems with two and three degrees of freedom, a plot in the phase plane is often more illuminating. You can do this using ParametricPlot:

It is easy to use a phase plane plot with Manipulate to allow you to vary initial conditions:

The Locator input allows you to drag the point to change initial conditions. The parameter T allows you to control the interval over which the problem is solved.

For a partial differential equation there are often several choices. For an example, consider Wolfram's nonlinear wave equation [more info]:

A good way to get an overall view of the solution is to use Plot3D:

An alternative that often gives good information about solution details is DensityPlot:

For time evolution equations like this, often the best intuition comes from an animation. Typically you will get the best results using ListAnimate. First make a list of plots at equal time intervals apart, all with the same PlotRange:

Now animate the list:

In this case it is a little hard to see the wave motion because of the varying background coming from a zero initial condition. An easy way to eliminate this is to solve the ODE corresponding to that and subtract it out: