MGM.09 Eigensense: Diagonalizable Matrices,
Matrix Exponential, Matrix Powers and Dynamical Systems
 LITERACY

Needs["LinearAlgebra`MatrixManipulation`"]; Needs["Graphics`Colors`"]; Off[General::"spell"]; Off[General::"spell1"]; Off[ParametricPlot3D::"ppcom"]; Off[ParametricPlot::"ppcom"]; Off[Plot::"plnr"]; SetOptions[Limit, Analytic -> True]; $Pre = Chop;

CMView = {2.7, 1.6, 1.2};

Vector Drawer

\(\(\( (*\ \(\(:\)\(Date : \ \ Copyright\ 2001\)\), \ 
      Math\ Everywhere, \ \(\(Inc\)\(.\)\)\ 
*) \)\(
\)\( (*
Original\ Conception\ to\ create\ a\ vector\ drawer\ is\ due\ to\ Bill\ Davis . 
Current\ code\ is\ by\ Bruce\ \(\(Carpenter\)\(.\)\)
*) \)\(
\)\( (*\ \ \(\(\(:\)\(Drawbacks : \ \ Since\ the\ vectors\ are\ drawn\ out\ of\)\)\ 

      \ \ \ \ \ context\), \ 
      the\ shapes\ of\ the\ arrowheads\ are\ only\ 
\ \ \ \ \ correct\ with\ AspectRatio\ set\ to\ \(\(Automatic\)\(.\)\)
*) \)\)\)

BeginPackage["Vector3D`","Graphics`Colors`"];

Axes3D::usage = "Axes3D[a, b] creates a Graphics3D object of cartesian axes with x, y, and z running from -a/3 to a, and with axes labels b units beyond the tips of the axes.  Axes3D[a] is Axes3D[a, a/8].";

Perpend::usage = "Perpend[a] returns a unit vector which is perpendicular to the vector a.";

Arrow::usage = "Arrow[a] produces a 2 or 3 dimensional vector from the origin to a. Arrow[a, Tail -> tail] gives a vector from tail to a.";
	
Vector::usage = "Vector[a, b] gives a 2D or 3D vector from a to b.";

ArrowHead::usage = "ArrowHead[a, vec] produces an arrowhead with its tip placed at the point a, pointing in the direction of the vector vec.";

Tail::usage = "Tail -> point puts the tail of the vector at point.";

Norm::usage = "Norm[vec] returns the Euclidean length of vec.";

Normalize::usage = "Normalize[vec] returns a unit vector in the direction of vec, provided vec is nonzero.";

Aperture::usage = "Aperture is the ratio of the radius of the base to the length of the head of a vector.";

TipSize::usage = "TipSize specifies an absolute size for the inner tip length of the head of a vector.";

TipRatio::usage = "TipRatio is the ratio of the inner length of the arrowhead to the length of the shaft of a vector.";

HeadRatio::usage = "HeadRatio is the ratio of the outer length of the arrowhead to the length of the shaft of a vector.";

HeadSize::usage = "HeadSize specifies an absolute size for the head of a vector.";

ScaleFactor::usage = "ScaleFactor specifies the amount to scale a vector in length and may be either a number or a pure function.";

ZeroVectorPointSize::usage = "ZeroVectorPointSize is the size of the point used to represent a zero vector.";

Options[Vector] = Options[Arrow] = Options[ArrowHead] =
{HeadRatio -> 0.18, TipRatio -> 0.14, Aperture -> 0.3, ScaleFactor -> 1, HeadType -> Polygon, ShaftQ -> True, EdgesQ -> True, VectorColor -> RGBColor[0,0,1], ShaftWidth -> 0.005, ZeroVectorPointSize -> 0.01};
		
Begin["`Private`"];

SetOptions[ParametricPlot,AspectRatio -> Automatic];
SetOptions[Plot,AspectRatio -> Automatic];
SetOptions[Graphics,AspectRatio -> Automatic];

Axes3D[u_,v_] := 
      Graphics3D[{
            {Blue,Line[{{-u/3,0,0},{u,0,0}}]},
                    Text["x",{u + v,0,0}],
            {Blue,Line[{{0,-u/3,0},{0,u,0}}]},
                    Text["y",{0, u + v,0}],
            {Blue,Line[{{0,0,-u/3},{0,0,u}}]},
                    Text["z",{0,0,u + v}]}]; 
Axes3D[u_] := Axes3D[u,u/8];
				
Norm[a_?VectorQ] := N[Sqrt[a.a]];

Normalize[a_?VectorQ] := If[a.a == 0, a, a/Norm[a]];

Perpend[a_?VectorQ] := Normalize[{a[[2]],-a[[1]]}]/;Length[a]==2;

Perpend[a_?VectorQ]:=
    Normalize[If[a[[1]]==0,{1,0,0},{a[[2]],-a[[1]],0}]]/;
      Length[a]==3;
      
Base3D = Table[{Cos[2 k Pi/8.], Sin[2 k Pi/8.]},{k,0,8}]; 

Vector[from_?VectorQ, to_?VectorQ, opts___] := Module[
   {sq, sw, ht, hs, hr, tr, ap, sf, vc, zvps, diff = to - from, tip},
   {sq, sw, ht, hs, hr, ts, tr, ap, sf, vc, zvps} = {ShaftQ, ShaftWidth, HeadType, HeadSize, HeadRatio, TipSize, TipRatio, Aperture, ScaleFactor, VectorColor, ZeroVectorPointSize} /. {opts} /. Options[Vector];
   If[from==to, Return[Graphics[{PointSize[zvps],vc,Point[from]}]]];
   diff = If[NumberQ[N[sf]], sf diff, sf[diff]];
   tip = from + diff;
   If[NumberQ[hs], hr = hs/Norm[diff]; tr = 0.75 hr];
   If[NumberQ[ts], tr = ts/Norm[diff]];
   Graphics[{If[sq,{vc,Thickness[sw],Line[{from,tip - tr diff}]},{}],
      With[{trans = ap hr Norm[diff] Perpend[diff]},
      {vc, Thickness[sw], ht[{tip,
                   (tip - hr diff + trans),
                   (tip - tr diff),
                   (tip - hr diff - trans),tip}]}]}]
] /; Length[from]==Length[to]==2

Vector[from_?VectorQ, to_?VectorQ, opts___] := Module[
   {sq, eq, sw, hs, hr, tr,ap, sf, vc, zvps, diff = to - from, tip},
   {sq, eq, sw, hs, hr, ap, sf, vc, zvps} = {ShaftQ, EdgesQ, ShaftWidth, HeadSize, HeadRatio, Aperture, ScaleFactor, VectorColor, ZeroVectorPointSize} /. {opts} /. Options[Vector];
   If[from==to, Return[Graphics3D[{PointSize[zvps],vc,Point[from]}]]];
   diff = If[NumberQ[N[sf]], sf diff, sf[diff]];
   tip = from + diff;
   If[NumberQ[hs], hr = hs/Norm[diff]];
   tr = hr/2;
   Graphics3D[{If[sq,{vc,Thickness[sw],Line[{from,tip-tr diff}]},{}], If[eq, {}, EdgeForm[]], {SurfaceColor[vc],
      With[{temp = Perpend[diff]},
      Polygon[Append[#,tip]]& /@ Partition[(tip - hr diff + #)&/@((ap hr Norm[diff] Base3D) . {temp,Normalize[Cross[temp,diff]]}),2,1]]}}]
] /; Length[from]==Length[to]==3


Arrow[a_, Tail->b_, opts___] := Vector[b,a+b,opts]

Arrow[a_, opts___] := Vector[Table[0,{Length[a]}],a,opts]

ArrowHead[a_, b_, opts___] := Vector[a-b,a,ShaftQ->False,opts];

End[];

EndPackage[];
Null

Graphics`Colors`GosiaGreen = 
        RGBColor[0,  0.392187,  0];

ThreeAxes[u,v]

ThreeAxes[u_, v_] := 
      Graphics3D[{{Blue, Line[{{-u, 0, 0}, {u, 0, 0}}]}, 
          Text["x", {u + v, 0, 0}], {Blue, 
            Line[{{0, -u, 0}, {0, u, 0}}]}, 
          Text["y", {0, u + v, 0}], {Blue, Line[{{0, 0, 0}, {0, 0, u}}]}, 
          Text["z", {0, 0, u + v}]}]; ThreeAxes[u_] := ThreeAxes[u, (u/8)]; ThreeAxes::"usage" = 
      "ThreeAxes[a,b] makes a standard cartesian axis graphics object with \
x, y, and z running from -a to a, and with axis labels b units beyond the \
tips of the axes.  ThreeAxes[a] is ThreeAxes[a,a/8].";

Clear[matrixplucker]; matrixplucker[expr_, vars_] := 
      Simplify[Outer[D, {expr}, vars]][[1
        ]]

In each of the following problems, indicate whether you  agree or disagree.
You are not asked to give any reasons for your response.

L.a)

If A is a diagonalizable 3D matrix and the eigenvalues of A are
          0.15, -0.52 and 2.74, 
then the eigenvalues of (E^(A t)) are
         (E^(0.15 t)), (E^(-0.52 t)) and (E^(2.74 t)) . 
Agree:.......   Disagree:....

L.b)

If A is a diagonalizable 3D matrix and the eigenvalues of A are
          0.15, -0.52 and 2.74, 
then the eigenvalues of (A^3) are
         (((0.15))^3), (((-0.52))^3) and (((2.74))^3) . 
Agree:.......   Disagree:....

L.c)

If A is a diagonalizable 3D matrix and the eigenvalues of A are
          -0.072,-0.023 and -0.914, 
Then you are guaranteed that as t gets large 
           (E^(A t)) . X -> {0, 0, 0}
Agree:.......   Disagree:....

L.d)

If A is a diagonalizable 2D matrix and the eigenvalues of A are
           0.52 and -2.74, 
then you are guaranteed that as t gets large 
           (E^(A t)) . X -> {0, 0}.
Agree:.......   Disagree:....

L.e)

If A is a diagonalizable 2D matrix and the eigenvalues of A are
           -0.52  +  I 3.84 and  -0.52  -  I 3.84, 
then you are guaranteed that as t gets large 
           (E^(A t)) . X -> {0, 0}.
Agree:.......   Disagree:....

L.f)

If A is a diagonalizable 2D matrix and the eigenvalues of A are
           0.52  +  I 3.84 and  0.52  -  I 3.84, 
then you are guaranteed that as t gets large 
           (E^(A t)) . X -> {0, 0}.
Agree:.......   Disagree:....

L.g)

If A is a diagonalizable 3D matrix and the eigenvalues of A are
          -0.34, -0.52  +  I 0.67 and  -0.52  -  I 0.67, 
then you are guaranteed that as t gets large 
           (E^(A t)) . X -> {0, 0, 0}.
Agree:.......   Disagree:....

L.h)

If A is a diagonalizable 3D matrix and the eigenvalues of A are
          0.83,  I 2.5 and  - I 2.5, 
then you are guaranteed that as t advances, 
           (E^(A t)) . X  spirals away from {0, 0, 0} (provided X ≠ {0, 0, 0}).
Agree:.......   Disagree:....

L.i)

If A is a diagonalizable matrix then the eigenvectors of A are the same as the eigenvectors of (E^(A t)) provided t ≠ 0.
Agree:.......   Disagree:....

L.j)

A diagonalizable 2D matrix A  calculates out to have 
       eigenvalue[1] = 1.5  with corresponding eigenvector[1] = {0.25, 1.0} 
and
       eigenvalue[2] =  -2.0 with corresponding eigenvector[2] = {0.5, 1.0}. 
so that  
        A . eigenvector[1] = 1.5 eigenvector[1]
and
        A . eigenvector[2] = -2.0 eigenvector[2]
Put
         {x[t], y[t]} = (E^(A t)) . starter 
so that {x[0], y[0]} = starter.
If starter is not a multiple of either eigenvector[1] or eigenvector[2], then as t gets large
             y[t]/x[t] -> 4.0.
Agree:.......   Disagree:....

L.k)

A diagonalizable 2D matrix A  calculates out to have 
       eigenvalue[1] = 1.5  with corresponding eigenvector[1] = {0.25, 1.0} 
and
       eigenvalue[2] =  -2.0 with corresponding eigenvector[2] = {0.5, 1.0}. 
so that  
        A . eigenvector[1] = 1.5 eigenvector[1]
and
        A . eigenvector[2] = -2.0 eigenvector[2]
Put
         {x[k], y[k]} = (A^k) . starter
so that {x[0], y[0]} = starter.

If starter is not a multiple of either eigenvector[1] or eigenvector[2], then as t gets large
             y[t]/x[t] -> 4.0.
Agree:.......   Disagree:....

L.l)

Here's a random 2D matrix A:

\(Clear[i, j, t]; 

    A\  = \ Table[Random[Real, {\(-5\), 5}], {i, 1, 2}, {j, 1, 2}]; 

    MatrixForm[A]\)

Here are two calculations - one of which is a correct calculation of (E^(A t)):

calculation1  =  
      MatrixForm[Simplify[ComplexExpand[E^(A t)]]]

calculation2  =  
      MatrixForm[Simplify[ComplexExpand[MatrixExp[A t]]]]

The first calculation of (E^(A t)) is correct and the second is wrong.
Agree:.......   Disagree:....

L.m)

Here's a 3D matrix A:

\(Clear[i, j]; 

    A\  = {{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0}}; 

    MatrixForm[A]\)

Here are two calculations - one of which is correct::

\(calculation1 = A\^2; 
MatrixForm[calculation1]\)

\(calculation2\  = \ MatrixPower[A, 2]; 
MatrixForm[calculation2]\)

The second calculation is a correct calculation of A . A.
Agree:.......   Disagree:....

L.n)

Although the theory of diagonalizable matrices was developed in the Basics in the setting of  2D matrices, the same theory works in the higher dimensions. 
Agree:.......   Disagree:....

L.o)

If A is a diagonalizable 3D matrix, then your are guaranteed that the eigenvectors of A span all of 3D.
Agree:.......   Disagree:....

L.p)

If A is a 4D matrix, and the eigenvectors of A do not span all of 4D, then your are guaranteed that A is not diagonalizable.
Agree:.......   Disagree:....

L.q)

If A is a diagonalizable matrix and none of the eigenvalues of A is zero, then A is invertible.
Agree:.......   Disagree:......