matlab题目 求高手解答

matlab题目 求高手解答 matlab题目 求解答
1到7的最短路径 给出matlab总程序

用matlab求最短路径,其使用的主要函数是digraph、shortestpath。求解方法:

A=[1 2 20;1 3 14;2 4 15;2 5 12;3 4 10;3 6 13;4 5 8;5 6 8;4 7 9;5 7 10;6 7 12]';

s = A(1,:);

t = A(2,:);

w = A(3,:);

G = digraph(s,t,w);

[path1,d] = shortestpath(G,1,7)

求解结果

path1 =     1     3     4     7  %路线

d =    33   %最短路径长度

最短路径线路图

温馨提示:答案为网友推荐,仅供参考