The supplied MATLAB file qrplt.m was run with several different choices for the matrix a.
>> a=randn(6)
a =
-0.4326 1.1892 -0.5883 -0.0956 -0.6918 -0.3999
-1.6656 -0.0376 2.1832 -0.8323 0.8580 0.6900
0.1253 0.3273 -0.1364 0.2944 1.2540 0.8156
0.2877 0.1746 0.1139 -1.3362 -1.5937 0.7119
-1.1465 -0.1867 1.0668 0.7143 -1.4410 1.2902
1.1909 0.7258 0.0593 1.6236 0.5711 0.6686
>> m=100
>> eig(a)
ans =
-2.1659 + 0.5560i
-2.1659 - 0.5560i
2.1493
0.2111 + 1.9014i
0.2111 - 1.9014i
-0.9548
The output can be found in this
figure.
As can be seen, the method converges quickly to the real eigenvalues.
It oscillates about the real parts of the two complex conjugate pairs
of eigenvalues. The size of the oscillation depends on the size of
the complex part.
>> b=randn(6)
b =
1.1908 -1.0565 -2.1707 0.5913 0.0000 0.7310
-1.2025 1.4151 -0.0592 -0.6436 -0.3179 0.5779
-0.0198 -0.8051 -1.0106 0.3803 1.0950 0.0403
-0.1567 0.5287 0.6145 -1.0091 -1.8740 0.6771
-1.6041 0.2193 0.5077 -0.0195 0.4282 0.5689
0.2573 -0.9219 1.6924 -0.0482 0.8956 -0.2556
>> a = b+diag([1,2,3,4,5,6])*inv(b)
a =
1.7067 -0.4659 -2.8400 0.2479 -0.5495 1.3031
-0.5578 2.9848 -2.0559 -2.0262 -0.8022 0.9146
0.5313 -0.7858 -3.2445 -0.2195 1.7625 1.2040
2.2196 -2.1473 -6.9495 -4.7347 2.1272 -0.7332
-0.7513 4.2147 1.3815 -1.8456 -1.2953 3.5042
6.6079 3.4731 -4.5124 -1.7294 3.2766 4.2340
>> m=100
>> eig(a)
ans =
5.7336
-5.5947
-3.9433
3.2202
3.0439
-2.8087
The output can be found in this
figure.
All the eigenvalues for this example are real, so we see
convergence to them all.
>> a=[[1 10]; [-1 1]]
a =
1 10
-1 1
>> m=300
m =
300
>> qrplt
Warning: This function is obsolete and may be removed in future versions.
Use CLF instead.
> In /afs/rpi.edu/campus/mathworks/matlab/5.11/toolbox/matlab/graphics/clg.m at line 11
In /afs/rpi.edu/home/93/mitchj/courses/math6800/qrplt.m at line 21
>> eig(a)
ans =
1.0000 + 3.1623i
1.0000 - 3.1623i
The output can be found in this
figure.
Here, the eigenvalues form a complex conjugate pair, so we get oscillation
about 1.
>> a = diag((1.5*ones(1,5)).^(0:4))+.01*(diag(ones(4,1),1)+diag(ones(4,1),-1))
a =
1.0000 0.0100 0 0 0
0.0100 1.5000 0.0100 0 0
0 0.0100 2.2500 0.0100 0
0 0 0.0100 3.3750 0.0100
0 0 0 0.0100 5.0625
>> m=30
>> eig(a)
ans =
5.0626
3.3750
2.2500
1.5001
0.9998
The output can be found in this
figure.
The eigenvalues are all real, and they are close to the diagonal entries.
The diagonal entries are in increasing order, so the algorithm has to
permute the matrix, resulting in a picture where the lines all cross.
>> qrplt;
>> perm=(5:-1:1)
perm =
5 4 3 2 1
>> a=a(perm,perm)
a =
5.0591 0.0760 0 0 0
0.0760 3.3733 0.0761 0 0
0.0000 0.0761 2.2475 0.0762 0
0.0000 -0.0000 0.0762 1.4964 0.0747
0.0000 -0.0000 0.0000 0.0747 1.0111
>> qrplt;
>> a=a(perm,perm)
a =
1.0000 0.0100 0.0000 -0.0000 0.0000
0.0100 1.5000 0.0100 -0.0000 0.0000
0.0000 0.0100 2.2500 0.0100 0.0000
0.0000 -0.0000 0.0100 3.3750 0.0100
0.0000 -0.0000 0.0000 0.0100 5.0625
The modified version of qrplt.m was used to create a plot of the log of the error for the fourth example. This shows that, asymptotically, the number of accurate digits increases linearly in the number of iterations. The speed of convergence depends linearly on the ratio of successive eigenvalues. In this example, the ratio is 1.5 for each successive pair.