Advertisement
jozz

WW

May 6th, 2013
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. << Combinatorica
  2. A = {1, 2, 3, 4, 5};
  3. ProdCart = CartesianProduct[A, A];
  4. H = {};
  5. For[i = 1, i <= Length[ProdCart], i++,
  6. L = ProdCart[[i]];
  7. If[ (L[[1]] - L[[2]])^2 == ProdCart[[i]], H = Append[H, L]];
  8. ];
  9.  
  10. Subscript[M, R] = ConstantArray[0, {Length[A], Length[A]}];
  11. For[i = 1, i <= Length[A], i++,
  12. For[j = 1, j <= Length[A], j++,
  13. If[ MemberQ[H, {A[[i]], A[[j]] } ] == True,
  14.  
  15. Subscript[M, R] = ReplacePart[Subscript[M, R], 1, {i, j}];
  16. ]
  17. ]
  18. ]
  19. AdjacencyGraph[Subscript[M, R], VertexLabels -> "Name",
  20. ImagePadding -> 10, DirectedEdges -> True]
  21. Print["\!\(\*SubscriptBox[\(M\), \(R\)]\) = " MatrixForm[Subscript[M,
  22. R]]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement