dijkstra怎么用matlab实现希望能直接给出代码,ps 要是给出注释就在完美不过了,邻接矩阵如下,求第4个点到各个点的最短距离[0 1 1 inf inf inf inf inf 1 0 1 inf inf inf inf inf 1 1 0 1 inf inf inf 1 inf inf 1 0 1 in

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 13:28:43
dijkstra怎么用matlab实现希望能直接给出代码,ps 要是给出注释就在完美不过了,邻接矩阵如下,求第4个点到各个点的最短距离[0 1 1 inf inf inf inf inf 1 0 1 inf inf inf inf inf 1 1 0 1 inf inf inf 1 inf inf 1 0 1 in
xU]OP+!) mՠ 5Bd͂(&:P:jm?sN{-2>%\M7}_u^HtGMc9(D&I:,=)o=AwpRk0WOYKf I2g tՇhb_gW.-J-\_++"vQ &g ,HFm!KqpCofbzf} ϱc[XTD! 0PM^l 9 E,Z"S[]jN |,N҉TFl1WCr8WNy&a ;3 Iy2 GK#7ɟ+= ScJcbB|zݢ"O/ /e">@p#5 }D#-3x.~]Vy([0:0`1(;[Ju>{*&z5TXW!dn86

dijkstra怎么用matlab实现希望能直接给出代码,ps 要是给出注释就在完美不过了,邻接矩阵如下,求第4个点到各个点的最短距离[0 1 1 inf inf inf inf inf 1 0 1 inf inf inf inf inf 1 1 0 1 inf inf inf 1 inf inf 1 0 1 in
dijkstra怎么用matlab实现
希望能直接给出代码,
ps 要是给出注释就在完美不过了,
邻接矩阵如下,求第4个点到各个点的最短距离
[0
1
1
inf
inf
inf
inf
inf
1
0
1
inf
inf
inf
inf
inf
1
1
0
1
inf
inf
inf
1
inf
inf
1
0
1
inf
1
inf
inf
inf
inf
1
0
1
inf
inf
inf
inf
inf
inf
1
0
1
inf
inf
inf
inf
1
inf
1
0
1
inf
inf
1
inf
inf
inf
1
0 ]
那个一列就是一行
度娘搞成这样了

dijkstra怎么用matlab实现希望能直接给出代码,ps 要是给出注释就在完美不过了,邻接矩阵如下,求第4个点到各个点的最短距离[0 1 1 inf inf inf inf inf 1 0 1 inf inf inf inf inf 1 1 0 1 inf inf inf 1 inf inf 1 0 1 in
a=[0 1 1 Inf Inf Inf Inf Inf;
1 0 1 Inf Inf Inf Inf Inf;
1 1 0 1 Inf Inf Inf 1;
Inf Inf 1 0 1 Inf 1 Inf;
Inf Inf Inf 1 0 1 Inf Inf;
Inf Inf Inf Inf 1 0 1 Inf;
Inf Inf Inf 1 Inf 1 0 1;
Inf Inf 1 Inf Inf Inf 1 0];
n=length(a); %节点个数
d=inf(1,n); %d存放到每点最短路径的向量
S=4;d(S)=0; %原点是第4点,同时也是目前的出发点
%原点到目前出发点距离是0
T=1:n;
T(T==S)=[]; %除了起始点,其他点都是未扩展的点
while ~isempty(T) %如果没有未扩展的点,那么完成全部点
tempd=a(S,T)+d(S);%计算:从目前出发点到所有未扩展点的距离+目前出发点到原点距离
mask=tempd