matlab用QR方法怎么求特征值,把程序写出来,谢谢

matlab用QR方法怎么求特征值,把程序写出来,谢谢,第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 01 0 4 0 0 00 1 0 3 0 00 0 1 0 2 00 0 0 1 0 10 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

qr Orthogonal-triangular decomposition.

[Q,R] = qr(A), where A is m-by-n, produces an m-by-n upper triangular

matrix R and an m-by-m unitary matrix Q so that A = Q*R.

[Q,R] = qr(A,0) produces the "economy size" decomposition.

If m>n, only the first n columns of Q and the first n rows of R are

computed. If m<=n, this is the same as [Q,R] = qr(A).

If A is full:

[Q,R,E] = qr(A) produces unitary Q, upper triangular R and a

permutation matrix E so that A*E = Q*R. The column permutation E is

chosen so that ABS(DIAG(R)) is decreasing.

[Q,R,e] = qr(A,'vector') returns the permutation information as a

vector instead of a matrix. That is, e is a row vector such that

A(:,e) = Q*R. Similarly, [Q,R,E] = qr(A,'matrix') returns a permutation

matrix E. This is the default behavior.

[Q,R,E] = qr(A,0) produces an "economy size" decomposition in which E

is a permutation vector, so that A(:,E) = Q*R.

X = qr(A) and X = qr(A,0) return the output of LAPACK's *GEQRF routine.

TRIU(X) is the upper triangular factor R.

If A is sparse:

R = qr(A) computes a "Q-less qr decomposition" and returns the upper

triangular factor R. Note that R = CHOL(A'*A). Since Q is often nearly

full, this is preferred to [Q,R] = qr(A).

R = qr(A,0) produces "economy size" R. If m>n, R has only n rows. If

m<=n, this is the same as R = qr(A).

[Q,R,E] = qr(A) produces unitary Q, upper triangular R and a

permutation matrix E so that A*E = Q*R. The column permutation E is

chosen to reduce fill-in in R.

[Q,R,e] = qr(A,'vector') returns the permutation information as a

vector instead of a matrix. That is, e is a row vector such that

A(:,e) = Q*R. Similarly, [Q,R,E] = qr(A,'matrix') returns a permutation

matrix E. This is the default behavior.

[Q,R,E] = qr(A,0) produces an "economy size" decomposition in which E

is a permutation vector, so that A(:,E) = Q*R.

[C,R] = qr(A,B), where B has as many rows as A, returns C = Q'*B.

The least-squares solution to A*X = B is X = R\C.

[C,R,E] = qr(A,B), also returns a fill-reducing ordering.

The least-squares solution to A*X = B is X = E*(R\C).

[C,R,e] = qr(A,B,'vector') returns the permutation information as a

vector instead of a matrix. That is, the least-squares solution to

A*X = B is X(e,:) = R\C. Similarly, [C,R,E] = qr(A,B,'matrix') returns

a permutation matrix E. This is the default behavior.

[C,R] = qr(A,B,0) produces "economy size" results. If m>n, C and R have

only n rows. If m<=n, this is the same as [C,R] = qr(A,B).

[C,R,E] = qr(A,B,0) additionally produces a fill-reducing permutation

vector E. In this case, the least-squares solution to A*X = B is

X(E,:) = R\C.

Example: The least squares approximate solution to A*x = b can be found

with the Q-less qr decomposition and one step of iterative refinement:

if issparse(A), R = qr(A)else R = triu(qr(A))end

x = R\(R'\(A'*b))

r = b - A*x

e = R\(R'\(A'*r))

x = x + e

See also lu, null, orth, qrdelete, qrinsert, qrupdate.


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8072182.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存