DiagonalizationWorksheet by Russell Blythrestart:with(plots):with(LinearAlgebra):
randomize(52):OutlineGoals of this worksheet:1) Construct a diagonalizable matrix which has specified eigenvalues and eigenvectors.2) Compute powers of diagonalizable matrices with ease!Diagonalizing matricesWe begin by applying the diagonalization process to a random 2x2 matrix.A := RandomMatrix(2,2,generator=rand(-10..10));Eigenvectors(A);
The eigenvectors appear in the first vector and corresponding eigenvectors appear as columns in the second matrix. If you prefer to work with only real values and the matrix above has complex-valued eigenvalues and eigenvectors, re-execute the two lines above until the eigenvalues (and eigenvectors) are real. Likewise if there is only one nonzero eigenvector displayed, or if the matrix is already diagonal.Extract the matrix of eigenvectors and find its inverse.Q := Eigenvectors(A)[2];
Q2 := MatrixInverse(Q);Diagonalize the matrix A using the matrix of eigenvectors. We also confirm that the diagonal entries of the diagonalized matrix are just the eigenvalues of A by computing numerical values.expand(simplify(Q2.A.Q));
evalf(simplify(Q2.A.Q));
evalf(Eigenvectors(A)[1]);We attempt the same computation with a random 3x3 matrix.A := RandomMatrix(3,3,generator=rand(-10..10));
MatrixInverse(A);
evalf(Eigenvectors(A)[1]);
Q := evalf(Eigenvectors(A)[2]);
Q2 := MatrixInverse(Q);
Q2.A.Q;Important: Read through this section before executing the next blockNote that the Maple procedure for finding the roots of cubics does not always recognize when the eigenvalues and/or eigenvectors turn out to be real - rounding error often produces complex values with very small imaginary parts. We can help the numerical evaluation by dropping the imaginary parts if all the entries should be real but appear with very small (nonzero) imaginary parts. Execute the following block of code only if the three eigenvalues are presumed to be real but very small imaginary parts appear as eigenvalues and eigenvalue entries.Evals := Eigenvectors(A)[1]:
Evecs := Eigenvectors(A)[2]:
Evals := map(Re,evalf(Evals));
Evecs := map(Re,evalf(Evecs));
Evecs2 := MatrixInverse(Evecs);
evalf(simplify(Evecs2.A.Evecs));Note the eigenvalues appear on the diagonal of Q2.A.Q (and any off-diagonal entries are within rounding error of zero).Constructing easily diagonalizable matricesHow might a professor find a diagonalizable matrix A to use as an example or on a test question? We see here how to use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1vdmFibGVsaW1pdHNHRjcvJSdhY2NlbnRHRjcvJTBmb250X3N0eWxlX25hbWVHRlYvJSVzaXplR0Y0LyUrZm9yZWdyb3VuZEdGQy8lK2JhY2tncm91bmRHRkMtRiM2JC1GZW82M1EqJnVtaW51czA7RidGaG8vRlxwRjdGXXAvRmBwUSQwZW1GJy9GY3BGY3IvRmVwRjdGZnBGaHBGW3FGXnFGYHFGYnFGZHFGZnFGaHFGanEtSSNtbkdGJDY5Rl1xRi9GMkY1L0Y5RjdGO0Y9Rj9GQUZERkZGSEZKRkxGTkZQRlJGVEZXRllGZW4vRmhuUSdub3JtYWxGJ0Zqbi1GZW82M1EiKUYnL0Zpb1EocG9zdGZpeEYnRltwRl1wRl9wL0ZjcFEydmVyeXRoaW5tYXRoc3BhY2VGJ0ZkcEZmcEZocEZbcUZecUZgcUZicUZkcUZmcUZocUZqcS8lMXN1cGVyc2NyaXB0c2hpZnRHUSIwRidGKw== for this purpose, where D is diagonal with entries that are eigenvalues and Q is the matrix whose columns are eigenvectors of A. We first randomly choose the eigenvalues, and then the eigenvectors corresponding to each of these eigenvectors. (Note we cannot use the variable D, which is a Maple system variable)DD := RandomMatrix(3,3,generator=rand(-5..5), outputoptions=[shape=diagonal]);Q1 := RandomVector(3,generator=rand(-3..3));
Q2 := RandomVector(3,generator=rand(-3..3));
Q3 := RandomVector(3,generator=rand(-3..3));Construct the matrix Q by assembling Q1, Q2, Q3 as its columnsQ := <Q1|Q2|Q3>;Check that {Q1,Q2,Q3} is independent.Rank(Q);If the rank of Q is not three, then the set {Q1, Q2, Q3} is not independent - go back and compute a new set.Now compute the matrix AA := Q . DD . Q^(-1);Check that the matrix A has the expected eigenvalues and eigenvectorsEigenvectors(A);Let's also check the characteristic polynomial of A.chp := CharacteristicPolynomial(A,x);factor(chp);Exercises:1) Find a 3 x 3 matrix B which has the eigenvectors and eigenvalues of your choice. Make all your eigenvalues nonzero, and all entries of your eigenvectors nonzero. (Don't reuse the variables DD or Q)2) The matrices A and B probably have fractional entries. How could the professor make sure that a matrix computed this way has only integer entries?Computing powers of matrices using diagonalizationCompute a high power of A using the diagonal matrix DD. First we choose an appropriate power:power := rand(8..20)();Raise the matrix DD to this power.powerDD := DD^power;A to the given power is now computed using QpowerA := Q . powerDD . Q^(-1);Check by direct calculation:A^power;Exercise:3) Compute some power of B between 8 and 20 using the same technique.