:

## A Procedure for Diagonalize a Matrix

Maple 13

Almost a couple of years ago,my quantum mechanics II course teacher was talking about the importance of diagonalizable matrices.Near the end of that lengthy class I was losing my attention & at that time he was talking about finding the diagonalization using Mathematica,but I was not sure.However,since I didn't/don't use Mathematica,I was trying to find the command to diagonalize a given matrix in Maple.I was using maple 13 then & I found a command  called "DiagonalMatrix()",but it was not what I wanted,it constructs a diagonal matrix from my given matrix,but diagonalization is a different thing.

A simple definition of what I'm talking about is this:

A square matrix say M is diagonalizable if there exists a non-singular matrix P such that inverse(P).A.P is a diagonal matrix.

I'm not going to bore you by talking about its importance & applications here.I think every advanced level physics undergrads know its importance & do some diagonalization now & then. So I'll get to the point.

Here is the procedure I wrote:

with(LinearAlgebra):

unprotect(D);

Diagonalize:=proc(A)                 #A is any square matrix

local Eval,Evec,P,Pinv,diagonal;

Eval,Evec:=Eigenvectors(A);

P:=Evec;

Pinv:=MatrixInverse(P);

diagonal:=Pinv.A.P  #  these are "." operator,not " * "

RETURN(`The matrix which diagonalizes A,i.e. P`=P,`The corresponding diagonal matrix is,D`=diagonal;

end proc;

Now,not every matrix is diagonalizable,only a non-singular P guarantees a diagonal matrix,but I didn't have to worry about it,if P is singular Maple  will take care of that by showing error message.

I don't know if this is any good to anybody,but I want to share anyway.

If the code I wrote above has any syntax error,this will help  Diagonalization.mw

NB:I didn't search inside Maple throughly,maybe  Maple can do it more simply.If I missed it,please someone let me know. ﻿