Finding eigenvalues of a symmetric matrix using QR Algorithm​
​Authors: Housam Binous and Ahmed Bellagi

We build a symmetric matrix called M1 using matrix M
In[]:=
M={{1,2,3,4},{0,-1,1,2},{2,3,4,5},{-1,2,-3,4}}//N
Out[]=
{{1.,2.,3.,4.},{0.,-1.,1.,2.},{2.,3.,4.,5.},{-1.,2.,-3.,4.}}
In[]:=
M1=(M+Transpose[M])/2
Out[]=
{{1.,1.,2.5,1.5},{1.,-1.,2.,2.},{2.5,2.,4.,1.},{1.5,2.,1.,4.}}
In[]:=
M1//MatrixForm
Out[]//MatrixForm=
1.
1.
2.5
1.5
1.
-1.
2.
2.
2.5
2.
4.
1.
1.5
2.
1.
4.
Eigenvalues of symmetric matrix M1are all real
In[]:=
Eigenvalues[M1]
Out[]=
{7.52454,3.09867,-2.12984,-0.49336}
QR algorithm:​
​
1- We start by setting
T
0
=M1 and decomposing it as follows:
T
0
=Q R​
where Q is an orthogonal matrix (meaning
T
Q
=
-1
Q
) and R is an upper triangular
matrix (also called right triangular matrix). See https://en.wikipedia.org/wiki/QR_decomposition.
​
2- Next, we define
T
1
=R
T
Q
and perform a similar QR decomposition this time on matrix
T
1
.


3- If we repeat this procedure a sufficient number of iterations say N (e.g., 500 in the coding below) then matrix
T
N
will be a diagonal matrix and its diagonal elements are the eigenvalues of the real symmetric matrix M1. These values are identical to the eigenvalues obtained with the built-in command Eigenvalues.
In[]:=
T[0]=M1;
In[]:=
T[0]//MatrixForm
Out[]//MatrixForm=
1.
1.
2.5
1.5
1.
-1.
2.
2.
2.5
2.
4.
1.
1.5
2.
1.
4.
In[]:=
i=0;
In[]:=
While[i<501,{{q,r}=QRDecomposition[T[i]];​​T[i+1]=r.Transpose[q];i++}]
In[]:=
T[500]//MatrixForm//Chop
Out[]//MatrixForm=
7.52454
0
0
0
0
3.09867
0
0
0
0
-2.12984
0
0
0
0
-0.49336