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[1]:=
Click for copyable input

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:

In[2]:=
Click for copyable input
Out[2]=

This plots the solution:

In[3]:=
Click for copyable input
Out[3]=

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:

In[4]:=
Click for copyable input
Out[4]=

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:

In[5]:=
Click for copyable input
Out[5]=

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 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]:

In[7]:=
Click for copyable input
Out[7]=

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

In[8]:=
Click for copyable input
Out[8]=

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

In[9]:=
Click for copyable input
Out[9]=

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:

In[10]:=
Click for copyable input

Now animate the list:

In[11]:=
Click for copyable input
Out[11]=

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:

In[12]:=
Click for copyable input
Out[12]=
In[13]:=
Click for copyable input
In[14]:=
Click for copyable input
Out[14]=