## 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: 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 This entry was posted in Mathematica. Bookmark the permalink.

### 1 Response to Mathematica: Stream plots for differential equations

1. mariusagm says:

Reblogged this on Mario A. G. Meza.