ExampleA.mws

> with(linalg);

Warning, the protected names norm and trace have been redefined and unprotected

[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp, QRdecomp, Wronskian, addcol, addrow, adj, adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix, charmat, charpoly, cholesky, col, cold...

> A:=matrix([[1, -1, 0, 0, 0, 0], [4, 5, 0, 0, 0, 0], [0, 0, 0, -1, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, -1, 0]]);

A := matrix([[1, -1, 0, 0, 0, 0], [4, 5, 0, 0, 0, 0], [0, 0, 0, -1, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, -1, 0]])

> charpoly(A, t);

t^6-6*t^5+11*t^4-12*t^3+19*t^2-6*t+9

> factor(%);

(t-3)^2*(t^2+1)^2

> factor(minpoly(A, t));

(t^2+1)*(t-3)^2

> #A is not diagonalizable because its minimal polynomial has repeated roots.

> B:=matrix([[3, 0, 0, 0, 0, 0], [0, 3, 0, 0, 0, 0], [0, 0, 0, -1, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, -1, 0]]);

B := matrix([[3, 0, 0, 0, 0, 0], [0, 3, 0, 0, 0, 0], [0, 0, 0, -1, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, -1, 0]])

> factor(charpoly(B,t));

(t-3)^2*(t^2+1)^2

> factor(minpoly(B, t));

(t-3)*(t^2+1)

> #B is diagonalizable over the complex numbers. Lets verify that this is indeed the minimal polynomial.

> multiply(B-3, B^2 + 1);

matrix([[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]])

> #Lets diagonalize B. We calculate the eigenspaces

> ESP(3) := kernel(B-3);

ESP(3) := {vector([1, 0, 0, 0, 0, 0]), vector([0, 1, 0, 0, 0, 0])}

> #Check:

> multiply(B, ESP(3)[1]);

vector([3, 0, 0, 0, 0, 0])

> ESP(I):=kernel(B-I);

ESP(I) := {vector([0, 0, I, 1, 0, 0]), vector([0, 0, 0, 0, -I, 1])}

> #Check:

> multiply(B, ESP(I)[1]);

vector([0, 0, -1, I, 0, 0])

> evalm(I*ESP(I)[1]);

vector([0, 0, -1, I, 0, 0])

> ESP(minusI):=kernel(B+I);

ESP(minusI) := {vector([0, 0, 0, 0, I, 1]), vector([0, 0, -I, 1, 0, 0])}

> #Check:

> multiply(B, ESP(minusI)[1]);

vector([0, 0, -1, -I, 0, 0])

> evalm(-I*ESP(minusI)[1]);

vector([0, 0, -1, -I, 0, 0])

> #By putting the eigenvectors together we get a matrix M that diagonalizes B

> M:=transpose(matrix([ESP(3)[1], ESP(3)[2], ESP(I)[1], ESP(I)[2], ESP(minusI)[1], ESP(minusI)[2]]));

M := matrix([[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, I, 0, -I, 0], [0, 0, 1, 0, 1, 0], [0, 0, 0, -I, 0, I], [0, 0, 0, 1, 0, 1]])

> multiply(inverse(M), B, M);

matrix([[3, 0, 0, 0, 0, 0], [0, 3, 0, 0, 0, 0], [0, 0, I, 0, 0, 0], [0, 0, 0, I, 0, 0], [0, 0, 0, 0, -I, 0], [0, 0, 0, 0, 0, -I]])

> #Later we'll learn about the Jordan form. If a matrix is diagonalizable then its Jordan form is diagonal. Else, it's not.

> jordan(A);

matrix([[I, 0, 0, 0, 0, 0], [0, -I, 0, 0, 0, 0], [0, 0, 3, 1, 0, 0], [0, 0, 0, 3, 0, 0], [0, 0, 0, 0, I, 0], [0, 0, 0, 0, 0, -I]])

> jordan(B);

matrix([[3, 0, 0, 0, 0, 0], [0, I, 0, 0, 0, 0], [0, 0, -I, 0, 0, 0], [0, 0, 0, 3, 0, 0], [0, 0, 0, 0, I, 0], [0, 0, 0, 0, 0, -I]])

> #In fact, Maple can givs us the transition matrix too.

> jordan(B, 'N');

matrix([[3, 0, 0, 0, 0, 0], [0, I, 0, 0, 0, 0], [0, 0, -I, 0, 0, 0], [0, 0, 0, 3, 0, 0], [0, 0, 0, 0, I, 0], [0, 0, 0, 0, 0, -I]])

> print(N);

matrix([[1, 0, 0, 0, 0, 0], [1, 0, 0, 1, 0, 0], [0, 1/2, 1/2, 0, 0, 0], [0, -1/2*I, 1/2*I, 0, 0, 0], [0, 1/2, 1/2, 0, 1/2, 1/2], [0, 1/2*I, -1/2*I, 0, 1/2*I, -1/2*I]])

> multiply(inverse(N), B, N);

matrix([[3, 0, 0, 0, 0, 0], [0, I, 0, 0, 0, 0], [0, 0, -I, 0, 0, 0], [0, 0, 0, 3, 0, 0], [0, 0, 0, 0, I, 0], [0, 0, 0, 0, 0, -I]])

>