Friday, May 2, 2014

Color-Coded Direction Fields

My differential equations professor mentioned that for autonomous systems of differential equations, direction fields help us visualize the direction, but not the speed, of solutions. However, he also mentioned that we might be able to encode the speed of solutions using colors – red for fast and blue for slow – so I took it upon myself to do that. The MATLAB code for this is available on my github.

For example, consider the linear Romeo and Juliet system of differential equations described in a paper called The Lighter Side of Differential Equations, where $x$ is Romeo's love for Juliet and $y$ is Juliet's love for Romeo:

\[
\left\{
\begin{array}{l}
x' = -0.2y \\
y' = 0.8x \\
\end{array}
\right.
\]

The solutions seem to be cyclic. Near the origin, the solutions are close to blue because they move relatively slowly, and near the edges, the solutions are close to red because they move more quickly.

For another example, consider a simple nonlinear predator-prey model. Let's say that $x$ is the population of rabbits and $y$ is the population of foxes:

\[
\left\{
\begin{array}{l}
x' = x - xy \\
y' = -y + xy \\
\end{array}
\right.
\]

Here, all of the vectors in the first quadrant are blue because, relative to the vector at $(-2, -2)$, they have very small magnitudes. We can zoom in near the critical point $(1, 1)$ to get a better idea of the relative speeds of solutions near that point:


This looks remarkably similar to the direction field for the Romeo and Juliet system! Shall I compare the love of Romeo and Juliet to foxes eating rabbits on a summer's day?