Eigenvectors and EigenvaluesWorksheet by Russell Blyth and Mike May, S.J.restart:with(plots):with(LinearAlgebra):OutlineGoals of this worksheet:1) Learn the Maple commands to compute eigenvectors2) Visualize the action of a matrix using eigenvectors and eigenvalues.3) Learn to do the step by step computations for finding eigenvectors.4) See some computations for which eigenvectors simplify problem solutions.Using Maple commands to compute eigenvectorsWe first look at the Maple commands for computing eigenvalues and eigenvectors. These commands let us work with eigenvectors and eigenvalues before we work through the detailed computations.We start with a randomly generated 2 by 2 matrix.A := RandomMatrix(2,2,generator=rand(-5..5));Eigenvectors(A);The output is an ordered pair, where the first entry is a vector of the Eigenvalues, and the second entry is a matrix whose columns are the corresponding eigenvectors.If we specify that the output should be a list, we get a set of triples, where the first entry of each triple is an eigenvalue, the second entry is its multiplicity as a root of the characteristic polynomial, and the third entry is a basis for the eigenspace corresponding to that eigenvector. We can extract this data if we first place these two triples into a sequence.evA := Eigenvectors(A, output='list');The eigenvalues:evA[1][1]; evA[2][1];The eigenvectors:[evA[1][3][1], evA[2][3][1]];Exercise:1) Use the following code to generate a symmetric 3 by 3 matrix. Find the Eigenvalues and Eigenvectors.B := RandomMatrix(3,3,generator=rand(-5..5),
outputoptions=[shape=symmetric]);Visualizing eigenvectors and eigenvalues in R2We can use eigenvectors and eigenvalues to give a description of the action of a transformation from R2 to R2. We break this into three cases, when the eigenvalues are real and distinct, when the eigenvalues are complex (must be conjugate in this case), and when the eigenvalues repeat (must be real in this case).Case 1 - Distinct real eigenvaluesTo produce distinct real eigenvalues, we start with a matrix that is symmetricA := RandomMatrix(2,2,generator=rand(-5..5),
outputoptions=[shape=symmetric]);We use the Eigenvector command to find the eigenvalues and corresponding eigenvectors.EigenA := [Eigenvectors(A)]:
EigenVecA := [Column(EigenA[2],1),Column(EigenA[2],2)];We plot the eigenvectors along with their images. The original vectors are graphed with double arrow heads and the images with single sided arrow heads.v1 := arrow(EigenVecA[1],color=blue, shape=arrow,thickness=5):
v2 := arrow(EigenVecA[2],color=red, shape=arrow,thickness=5):
Av1 := arrow(A.EigenVecA[1],color=navy, shape=harpoon,thickness=3):
Av2 := arrow(A.EigenVecA[2],color=green, shape=harpoon,thickness=3):
display({v1, v2, Av1, Av2},scaling=constrained);Notice that the images of the eigenvectors are scalar multiples of the eigenvectors.Exercise:2) For the matrix A above, give a basis of R2 composed of eigenvectors. Describe the action of A on this basis.Explain how A acts on a linear combination of the vectors in this basis.Case 2 - Complex eigenvaluesWhen the eigenvalues are complex, it means the action of the transformation involves a rotation. In the 2 by 2 case this can be guaranteed by letting the two entries on the main diagonal be close in value and the entries on the off diagonal be of opposite signs.A := <<1,3> | <-4,2>>;
EigenA := [Eigenvectors(A)];In that case we use the Eigenplot command from the Student[LinearAlgebra] package to visualize what happens.Student[LinearAlgebra][EigenPlot](A, showunitvectors=true,
scaling=constrained, axes=normal, numvectors=8);The graph has unit vectors starting at the origin in yellow, with the respective images in green starting at the head of the original vector. In this case we have a counterclockwise rotation along with an expansion.Case 3 - Repeated eigenvectorsThe third case is repeated real eigenvalues. Sometimes, in this case, Maple does not produce a basis of eigenvectors. We will come back to this case in later sections.A := <<2,0> | <2,2>>;
Eigenvectors(A);
Eigenvectors(A,output='list');Student[LinearAlgebra][EigenPlot](A, showunitvectors=true,
scaling=constrained, axes=normal, numvectors=8);Eigenvectors(A,output='list');Exercise:3) Randomly generate a 2 by 2 matrix with distinct real eigenvalues. (You may need to try the generation several times.) Using the result of the Eigenvectors command, describe the action of the transformation. Plot a graph that illustrates your description.4) Randomly generate a 2 by 2 matrix with complex eigenvalues. (You may need to try the generation several times.) Using the result of the Student[LinearAlgebra][Eigenplot] command, describe the action of the transformation. Visualizing eigenvectors and eigenvalues in R3Case 1 - Distinct real eigenvaluesWe can repeat the process for 3 by 3 matrices, but we need some computational trickery. Since solving cubics involves using complex numbers in a way that does not easily simplify, we evaluate the decimal approximation of the matrix of eigenvectors. The imaginary part is small enough to be roundoff error, so we eliminate it before graphing.A := RandomMatrix(3,3,generator=rand(-5..5),
outputoptions=[shape=symmetric]);
EigenA := [Eigenvectors(A)]:
EigenA1 := evalf(EigenA[2]);
EigenA2 := map(Re,evalf(EigenA[2]));
EigenVecA := ([Column(EigenA2,1),Column(EigenA2,2),Column(EigenA2,3)]):
v1 := arrow(EigenVecA[1],color=blue, shape=arrow,thickness=3):
v2 := arrow(EigenVecA[2],color=red, shape=arrow,thickness=3):
v3 := arrow(EigenVecA[3],color=brown, shape=arrow,thickness=3):
Av1 := arrow(A.EigenVecA[1],color=navy, shape=harpoon,thickness=3):
Av2 := arrow(A.EigenVecA[2],color=green, shape=harpoon,thickness=3):
Av3 := arrow(A.EigenVecA[3],color=yellow, shape=harpoon,thickness=3):
display({v1, v2,v3, Av1, Av2,Av3},scaling=constrained, axes=normal);Exercise:5) Create a symmetric 3 by 3 matrix B whose entries are the first 6 digits of your social security number.Find a basis of eigenvectors and plot the action of B on these vectors.Case 2 - Complex eigenvalues
For the 3 by 3 case we remove the symmetric option and repeat the Random Matrix until we get one with complex eigenvalues.A := RandomMatrix(3,3,generator=rand(-5..5));
EigenA := [Eigenvectors(A)]:
EvalsA := evalf(EigenA[1]);
EvecsA := evalf(EigenA[2]);
We can then use Eigenplot to see what is happening.Student[LinearAlgebra][EigenPlot](A,axes=boxed,
showsphere=false,eigenoptions=[shape=arrow, thickness=3,color=blue],
scaling=constrained, numvectors=1);The blue vector is an eigenvector. Shifting the image so that we are looking at the blue vector head on shows the same kind of rotation for the projection.Computing eigenvalues and eigenvectors - Step by stepWhile it is useful to have a simple Maple command for Eigenvalues and Eigenvectors, we would also like to step through the computations, so that we can do this by hand if needed.First define a matrix and the identity of the same size.A := <<-1,0,5>|<0,4,0>|<5,0,-1>>;
I3 := IdentityMatrix(3);Compute the characteristic polynomial, which is det(A - x*I3)chpol := Determinant(A - x*I3);Set equal to zero and solve.AEvals := [solve(chpol = 0,x)];Compute the basis of the first eigenspace by finding the basis of the corresponding nullspace.AEbasis1 := NullSpace(A-AEvals[1]*I3);Repeat for the second eigenvalueAEbasis2 := NullSpace(A-AEvals[2]*I3);Check that these eigenspace basis vectors are in fact eigenvectors of A[AEbasis1[1], AEvals[1], A . AEbasis1[1]];
[AEbasis2[1], AEvals[2], A . AEbasis2[1]];
[AEbasis2[2], AEvals[3], A . AEbasis2[2]];Note that these vectors are the correct multiples of the eigenvectors.Exercises6) Follow the recipe above to find the eigenvalues and eigenvectors of the matrix B.B := Matrix(3,3,[[0,1,1],[0,2,0],[-2,1,3]]);7) Repeat for the matrix C.C := Matrix(3,3,[[4,-3,1],[4,-1,0],[1,7,-4]]);When you are done: what can you say about the matrix C?Using eigenvalues and eigenvectors to ease computationWith A defined above, we want to compute the product of a power of A times a vector.We'll easily compute NiMqJCUiQUciI0Q= * X where X = NiMpNyUiIiMiIiQsJCIiIiEiIiUidEc=First note that the three eigenvectors which we computed earlier form a basis for NiMqJCUiUkciIiQ=AEMat := <AEbasis1[1] | AEbasis2[1] | AEbasis2[2]>;
Rank(AEMat);Now find the coefficients of X with respect to the basis above.X := <2,3,-1>;
Xcvec := LinearSolve(AEMat,X);Now NiMqJCUiQUciI0Q= * X is computed as follows:Xcvec[1]*AEvals[1]^25*AEbasis1[1]
+ Xcvec[2]*AEvals[2]^25*AEbasis2[1]
+ Xcvec[3]*AEvals[2]^25*AEbasis2[2];Note that this calculation involved no matrix multiplications. What advantage might this have?Maple will actually compute directly, so let's check.A^25 . X;Exercise:8) Given the matrix B defined below, compute NiMqJCUiQkciIzg= * X (X as above) using eigenvalues and eigenvectors. Check by direct computation. (Note we cannot use this technique for powers of C, since we can't find a basis of eigenvectors of C.)B := Matrix(3,3,[[0,1,1],[0,2,0],[-2,1,3]]);