Created
November 26, 2018 23:51
-
-
Save saifsmailbox98/b533184451addb3bc6afbc3bd5074998 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b = isprime(6); | |
c = isprime([0 1 2 3 4 5 6 7]); | |
disp(b); | |
disp(c); | |
>> mupad; | |
numlib::lincongruence(7,19,23); | |
[6] | |
prim.m | |
a = {'A' 'A' 'B' 'B' 'B' 'C' 'D' 'D' 'E' 'E' 'F'}; | |
b = {'B' 'D' 'C' 'D' 'E' 'E' 'E' 'F' 'F' 'G' 'G'}; | |
c = [7 5 8 9 7 5 15 6 8 9 11]; | |
G = graph(a, b, c); | |
P = plot(G, 'EdgeLabel', G.Edges.Weight); | |
T = minspantree(G, 'Method', 'dense'); | |
highlight(P, T); | |
L = sum(T.Edges.Weight); | |
disp('Length of the minimum spanning tree ='); | |
disp(L); | |
>> prim | |
Length of the minimum spanning tree = | |
39 | |
kruskal.m | |
a = {'1' '1' '2' '2' '3' '3' '4' '4' '4' '4' '5', '7'}; | |
b = {'2' '4' '4' '5' '1' '6' '3' '5' '6' '7' '7', '6'}; | |
c = [2 1 3 10 4 5 2 2 8 4 6 1]; | |
G = graph(a, b, c); | |
P = plot(G, 'EdgeLabel', G.Edges.Weight); | |
T = minspantree(G, 'Method', 'sparse'); | |
highlight(P, T); | |
L = sum(T.Edges.Weight); | |
disp('Length of the minimum spanning tree ='); | |
disp(L); | |
>> kruskal | |
Length of the minimum spanning tree = | |
12 | |
dijkstra.m | |
a = {'1' '1' '2' '2' '5' '3' '3' '4'}; | |
b = {'2' '3' '5' '4' '6' '5' '4' '6'}; | |
c = [1 3 5 4 2 4 5 6]; | |
G = digraph(a, b, c); | |
P = plot(G, 'EdgeLabel', G.Edges.Weight); | |
[path, d] = shortestpath(G,'1','6'); | |
T = shortestpathtree(G,{'1'},{'6'}); | |
highlight(P, T); | |
disp('Shortest Path:'); | |
disp(path); % Shortest path | |
disp('Length of the shortest Path ='); | |
disp(d); % Length of the shortest path | |
>> dijkstra | |
Shortest Path: | |
'1' '2' '5' '6' | |
Length of the shortest Path = | |
8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment