用QR方法解决特征值问题 写出matlab程序源码。

2024-12-20 14:18:57
推荐回答(2个)
回答1:

前面的函数是求特征值的函数,后面的是调用的例子和验证

function l = rqrtz(A,M)
%QR算法求矩阵全部特征值
%已知矩阵:A
%迭代步数:M
%求得的矩阵特征值:l

A = hess(A);
for i=1:M
N = size(A);
n = N(1,1);
u = A(n,n);
[q,r]=qr(A-u*eye(n,n));
A = r*q+u*eye(n,n);
l = diag(A);
end

A=[0 5 0 0 0 0;1 0 4 0 0 0;0 1 0 3 0 0;0 0 1 0 2 0;0 0 0 1 0 1;0 0 0 0 1 0]

A =

0 5 0 0 0 0
1 0 4 0 0 0
0 1 0 3 0 0
0 0 1 0 2 0
0 0 0 1 0 1
0 0 0 0 1 0

>> rqrtz(A,50)

ans =

-3.2030
3.2030
-1.8837
1.8837
-0.6167
0.6167

>> eig(A)

ans =

-3.3243
3.3243
-1.8892
-0.6167
1.8892
0.6167

回答2:

function l = rqrtz(A,M)
%QR算法求矩阵全部特征值
%已知矩阵:A
%迭代步数:M
%求得的矩阵特征值:l

A = hess(A);
for i=1:M
N = size(A);
n = N(1,1);
u = A(n,n);
[q,r]=qr(A-u*eye(n,n));
A = r*q+u*eye(n,n);
l = diag(A);
end

------------------------------------
A=[0 5 0 0 0 0;1 0 4 0 0 0;0 1 0 3 0 0;0 0 1 0 2 0;0 0 0 1 0 1;0 0 0 0 1 0]

A =

0 5 0 0 0 0
1 0 4 0 0 0
0 1 0 3 0 0
0 0 1 0 2 0
0 0 0 1 0 1
0 0 0 0 1 0

>> rqrtz(A,50)

ans =

-3.2030
3.2030
-1.8837
1.8837
-0.6167
0.6167

>> eig(A)

ans =

-3.3243
3.3243
-1.8892
-0.6167
1.8892
0.6167