Mathematica: Stream plots for differential equations

It is very easy to use Mathematica to make stream plots for differential equations.

Stream plots for a single equation

Consider the example

\frac{dy}{dt} = (y-y^3)\cos{(t)}.

Points on a solution curve to this equation will take the form (t,y(t)). Thus the slope will look like

(\frac{d}{dt}[t],\frac{d}{dt}[y(t)]) = (1,\frac{dy}{dt}).

Using the differential equation, we see that

\left((1,\frac{dy}{dt}\right) = \left(1, (y-y^3)\cos{(t)}\right).

Thus this is what we want to plot. The Mathematica code for this is the following:

StreamPlot[{1,(y-y^3) Cos[t]}, {t,0,5},{y,-2,2}]

The output is this:

FirstStreamPlot

Notice the following:

  • The command {1,(y-y^3) Cos[t]} gives the slope to be plotted at each point.
  • The command {t,0,5} gives the range of t values.
  • The command {y,-2,2} gives the range of y values.

Notice also that it is easy to see the equilibrium solutions on the picture – how cool is that!

Stream plots for systems

For a system of the form

\dfrac{dx}{dt} = f(x,y)    \\    \\    \dfrac{dy}{dt} = g(x,y)

we can make a stream plot on the domain a\leq x \leq b, c\leq y\leq d using

StreamPlot[{f(x,y),g(x,y)},{x,a,b},{y,c,d}]

For example, the stream plot for the system

\dfrac{dx}{dt} = x(1-x) + \sin{y}    \\    \\    \dfrac{dy}{dt} = y^2 + \frac{x}{e^y}

is generated using the code

StreamPlot[{x(1-x)+Sin[y], y^2+x/Exp[y]},{x,-2,2},{y,-3,3}]

The result is

RandomHarvest

Advertisements
This entry was posted in Mathematica. Bookmark the permalink.

One Response to Mathematica: Stream plots for differential equations

Leave a comment here

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s