使矩阵的n次方等于它的n-1次方,求相等时的矩阵
如图,已知矩阵A+I,求矩阵R,求解各位大神,感谢感谢或者有没有大神能帮忙编个程序,在这个矩阵的n次幂和n-1次幂相等时的程序,用if语句啥的,感谢感谢...
如图,已知矩阵A+I,求矩阵R,求解各位大神,感谢感谢
或者有没有大神能帮忙编个程序,在这个矩阵的n次幂和n-1次幂相等时的程序,用if语句啥的,感谢感谢 展开
或者有没有大神能帮忙编个程序,在这个矩阵的n次幂和n-1次幂相等时的程序,用if语句啥的,感谢感谢 展开
1个回答
展开全部
主程序
clc;clear
B = [
1,0,0,0,1,0,0,0,1;
1,1,0,0,0,0,0,0,0;
0,0,1,1,0,0,0,1,0;
0,0,0,1,0,1,0,0,0;
0,0,0,0,1,0,0,0,0;
0,0,0,1,0,1,0,0,0;
0,1,0,0,0,0,1,0,0;
0,0,1,0,0,0,0,1,0;
0,0,0,0,0,0,0,0,1;
];
Ncr =1000;%假如要1000次连乘
[R,N] = KDmat(B,Ncr);%计算可达矩阵
函数程序
function A = lgproduct(B,C)
B = B==1;
C = C==1;
[m,n] = size(B);
[p,q] = size(C);
A = [];
if(n==p)
A = zeros(m,q)~=0;
for i = 1:1:m
for j = 1:1:q
A(i,j) = any(B(i,:)&C(:,j)');
end
end
end
end
函数程序
function [R,N] = KDmat(B,Ncr)
ct = 0;
R = B;
while(1)
Rold = R;
R = lgproduct(R,B);
ct = ct + 1;
if(all(all(R==Rold))||ct>=Ncr)
N = ct;
break;
end
end
end
最后结果
R =
1 0 0 0 1 0 0 0 1
1 1 0 0 1 0 0 0 1
0 0 1 1 0 1 0 1 0
0 0 0 1 0 1 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 1 0 1 0 0 0
1 1 0 0 1 0 1 0 1
0 0 1 1 0 1 0 1 0
0 0 0 0 0 0 0 0 1
N =
3
clc;clear
B = [
1,0,0,0,1,0,0,0,1;
1,1,0,0,0,0,0,0,0;
0,0,1,1,0,0,0,1,0;
0,0,0,1,0,1,0,0,0;
0,0,0,0,1,0,0,0,0;
0,0,0,1,0,1,0,0,0;
0,1,0,0,0,0,1,0,0;
0,0,1,0,0,0,0,1,0;
0,0,0,0,0,0,0,0,1;
];
Ncr =1000;%假如要1000次连乘
[R,N] = KDmat(B,Ncr);%计算可达矩阵
函数程序
function A = lgproduct(B,C)
B = B==1;
C = C==1;
[m,n] = size(B);
[p,q] = size(C);
A = [];
if(n==p)
A = zeros(m,q)~=0;
for i = 1:1:m
for j = 1:1:q
A(i,j) = any(B(i,:)&C(:,j)');
end
end
end
end
函数程序
function [R,N] = KDmat(B,Ncr)
ct = 0;
R = B;
while(1)
Rold = R;
R = lgproduct(R,B);
ct = ct + 1;
if(all(all(R==Rold))||ct>=Ncr)
N = ct;
break;
end
end
end
最后结果
R =
1 0 0 0 1 0 0 0 1
1 1 0 0 1 0 0 0 1
0 0 1 1 0 1 0 1 0
0 0 0 1 0 1 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 1 0 1 0 0 0
1 1 0 0 1 0 1 0 1
0 0 1 1 0 1 0 1 0
0 0 0 0 0 0 0 0 1
N =
3
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询