Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- << Combinatorica
- A = {1, 2, 3, 4, 5};
- ProdCart = CartesianProduct[A, A];
- H = {};
- For[i = 1, i <= Length[ProdCart], i++,
- L = ProdCart[[i]];
- If[ (L[[1]] - L[[2]])^2 == ProdCart[[i]], H = Append[H, L]];
- ];
- Subscript[M, R] = ConstantArray[0, {Length[A], Length[A]}];
- For[i = 1, i <= Length[A], i++,
- For[j = 1, j <= Length[A], j++,
- If[ MemberQ[H, {A[[i]], A[[j]] } ] == True,
- Subscript[M, R] = ReplacePart[Subscript[M, R], 1, {i, j}];
- ]
- ]
- ]
- AdjacencyGraph[Subscript[M, R], VertexLabels -> "Name",
- ImagePadding -> 10, DirectedEdges -> True]
- Print["\!\(\*SubscriptBox[\(M\), \(R\)]\) = " MatrixForm[Subscript[M,
- R]]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement