满意答案
565433fdf
2013.08.27
采纳率:49% 等级:12
已帮助:7012人
%file maxtr.m
function [mt,my]=maxtr(a,eps)
%a the matrix
%eps the accept error ,you decide it
%mt the maximum eigenvalue of the matrix
%my the corresponding eigenvector of mt
n=length(a);
x0=diag(ones(n));
k=1;
x=a*x0;
while norm(x-x0)>eps
k=k+1;
q=x;
y=x/maxnorm(x);
x=a*y;
x0=q;
end
mt=maxnorm(x);
my=y;
%%建立maxtr.m文件
%file maxnorm.m
function t=maxnorm(a)
%the maximum element of the array
n=length(a);
t=0;
for i=1:n
if abs(a(i)/max(abs(a)))>=1
t=a(i);
end
end
%%再建立maxnorm.m文件
运行
A=[1 8/5 8/7 2 8/9
5/8 1 5/7 5/4 5/9
7/8 7/5 1 7/4 7/9
1/2 4/5 4/7 1 4/9
9/8 9/5 9/7 9/4 1];
[mt,my]=maxtr(A,0.0001)
结果
mt =
5
my =
0.8889
0.5556
0.7778
0.4444
1.0000
00分享举报