求帮忙解答一matlab简单程序 ,总是运行结果出不来
function[D,Node]=floyd(a)n=size(a,1);D=a;Node=zeros(n,n);fori=1:nforj=1:nifD(i,j)~=in...
function [D,Node] = floyd( a )
n = size(a,1);
D = a; Node = zeros (n,n);
for i = 1 : n
for j = 1 : n
if D(i,j) ~= inf;
Node(i,j) = j;
end
end
end
for k = 1 : n
for i = 1 : n
for j = 1 : n
if D(j,k) + D(k,j) < D(i,j)
D(i,j) = D(j,k) + D(k,j);
Node(i,j) = Node(i,k);
end
end
end
end
我不知道如何给a定义,a是一个路网邻接矩阵,它的值为
a =[0,5,0,3,0,0,0,0,0;5,0,7,0,4,0,0,0,0;0,7,0,6,0,10,0,0,0;3,0,6,0,6,0,0,0,0;0,4,0,6,0,13,0,0,0;0,0,10,0,13,0,7,9,0;0,0,0,0,0,7,0,0,11;0,0,0,0,0,9,0,0,14;0,0,0,0,0,0,11,14,0] 展开
n = size(a,1);
D = a; Node = zeros (n,n);
for i = 1 : n
for j = 1 : n
if D(i,j) ~= inf;
Node(i,j) = j;
end
end
end
for k = 1 : n
for i = 1 : n
for j = 1 : n
if D(j,k) + D(k,j) < D(i,j)
D(i,j) = D(j,k) + D(k,j);
Node(i,j) = Node(i,k);
end
end
end
end
我不知道如何给a定义,a是一个路网邻接矩阵,它的值为
a =[0,5,0,3,0,0,0,0,0;5,0,7,0,4,0,0,0,0;0,7,0,6,0,10,0,0,0;3,0,6,0,6,0,0,0,0;0,4,0,6,0,13,0,0,0;0,0,10,0,13,0,7,9,0;0,0,0,0,0,7,0,0,11;0,0,0,0,0,9,0,0,14;0,0,0,0,0,0,11,14,0] 展开
1个回答
展开全部
你先试着执行函数主体部分吧,结果可能会让你有思路
a=[0,5,0,3,0,0,0,0,0;5,0,7,0,4,0,0,0,0;0,7,0,6,0,10,0,0,0;3,0,6,0,6,0,0,0,0;0,4,0,6,0,13,0,0,0;0,0,10,0,13,0,7,9,0;0,0,0,0,0,7,0,0,11;0,0,0,0,0,9,0,0,14;0,0,0,0,0,0,11,14,0];
% function [D,Node] = floyd( a )
n = size(a,1);
D = a; Node = zeros (n,n);
for i = 1 : n
for j = 1 : n
if D(i,j) ~= inf;
Node(i,j) = j;
end
end
end
for k = 1 : n
for i = 1 : n
for j = 1 : n
if D(j,k) + D(k,j) < D(i,j)
D(i,j) = D(j,k) + D(k,j);
Node(i,j) = Node(i,k);
end
end
end
end
D
Node
a=[0,5,0,3,0,0,0,0,0;5,0,7,0,4,0,0,0,0;0,7,0,6,0,10,0,0,0;3,0,6,0,6,0,0,0,0;0,4,0,6,0,13,0,0,0;0,0,10,0,13,0,7,9,0;0,0,0,0,0,7,0,0,11;0,0,0,0,0,9,0,0,14;0,0,0,0,0,0,11,14,0];
% function [D,Node] = floyd( a )
n = size(a,1);
D = a; Node = zeros (n,n);
for i = 1 : n
for j = 1 : n
if D(i,j) ~= inf;
Node(i,j) = j;
end
end
end
for k = 1 : n
for i = 1 : n
for j = 1 : n
if D(j,k) + D(k,j) < D(i,j)
D(i,j) = D(j,k) + D(k,j);
Node(i,j) = Node(i,k);
end
end
end
end
D
Node
ZESTRON
2024-09-04 广告
2024-09-04 广告
在Dr. O.K. Wack Chemie GmbH,我们高度重视ZESTRON的表界面分析技术。该技术通过深入研究材料表面与界面的性质,为提升产品质量与可靠性提供了有力支持。ZESTRON的表界面分析不仅涵盖了相变化、化学反应、吸附与解吸...
点击进入详情页
本回答由ZESTRON提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询