Two dimensional ODEs

This notebook illustrates some Mathematica commands for visualizing two dimensional phase portraits for autonomous differential equations of the form {x’[t],y’[t]} = {f[x,y],g[x,y]}.   Using the Mathematica functions VectorPlot or StreamPlot, we can immediately get an approximate phase portrait.   Here is a simple linear example

a = 1;
b= 0;
c=0;
d=-1;
f[x_,y_]:=a*x+b*y;
g[x_,y_]:=c*x+d*y;
VectorPlot[{f[x,y],g[x,y]},{x,-1,1},{y,-1,1},FrameLabel->{x,y}]
StreamPlot[{f[x,y],g[x,y]},{x,-1,1},{y,-1,1},FrameLabel->{x,y}]

Using Mathematica’s Manipulate command we can visualize lots of linear systems by just moving some sliders.

Manipulate[StreamPlot[{a*x+b*y,c*x+d*y},{x,-1,1},{y,-1,1},FrameLabel->{x,y},PlotLabel->MatrixForm[{{a,b},{c,d}}]],
{{a,1},-1,1},{{b,0},-1,1},{{c,0},-1,1},{{d,1},-1,1}]

Here is a nonlinear, autonomous example: the pendulum with friction.  The second order ODE from Newton’s law is
x’’[t] + d*x’[t] +Sin[x[t]] == 0 . It can be converted to a first order system in the {x,v} plane as follows

f[x_,v_]:=v;
g[x_,v_]:=-Sin[x]-d*v;
d=0.5;

StreamPlot[{f[x,y],g[x,y]},{x,-2*Pi,2*Pi},{y,-2,2},FrameLabel->{x,v},AspectRatio->1/(Pi)]

Eigenvalues and Eigenvectors

We can use Mathematica to find eigenvalues and eigenvectors.  These can be used to find the canonical forms.

Here is an example with two real eigenvalues.

A = {{-2,2},{3,-1}}; A//MatrixForm
evals = Eigenvalues[A]
evects = Eigenvectors[A]

Define a matrix T with the eigenvectors as columns.  The result evects above has these vectors as rows so we just need the transpose. Then we get the normal form.

T=Transpose[evects]; T//MatrixForm
B= Inverse[T].A.T;B//MatrixForm

Next, an example with complex eigenvalues.

A = {{0,1},{-2,-1}}; A//MatrixForm
evals = Eigenvalues[A]
evects = Eigenvectors[A]

The columns of T are the real and imaginary parts of one of the complex eigenvectors.

Z1 = evects[[1]]
X1= Re[Z1]; Y1= Im[Z1];
T= {X1,Y1}//Transpose; T//MatrixForm
B= Inverse[T].A.T;B//MatrixForm

Finally, an example with repeated real eigenvalues and only one independent eigenvector.

A = {{0,1},{-4,4}}; A//MatrixForm
evals = Eigenvalues[A]
evects = Eigenvectors[A]

We can generate the columns of a T matrix as follows:  choose any noneigenvector as the second column, then multiply it by A-2I to get the first column.

V2={0,1};
V1= (A-2*IdentityMatrix[2]).V2;
T =  {V1,V2}//Transpose;T//MatrixForm
B= Inverse[T].A.T;B//MatrixForm

If we use V1 and k*V2 instead, we can change the off diagonal 1 to some other value.

T =  {V1,0.1*V2}//Transpose;T//MatrixForm
B= Inverse[T].A.T;B//MatrixForm