Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. n = 5;
  2. pts = RandomReal[{-10, 10}, {n, 3}]
  3. DD = Table[(pts[[i]] - pts[[j]]).(pts[[i]] - pts[[j]]), {i, 1, n}, {j, 1, n}]
  4. For[i = 1; s = 0, i <= n, i++,
  5. For[j = i, j <= n, j++, If[i != j, s += ((Subscript[x, i] - Subscript[x, j])^2 + (Subscript[y, i] - Subscript[y, j])^2 + (Subscript[z, i] - Subscript[z, j])^2 -DD[[i, j]])^2]
  6. ]
  7. ]
  8. vars = Variables[s]
  9. sol = Minimize[s, vars]
  10. ptsol = Table[{Subscript[x, k], Subscript[y, k], Subscript[z, k]} /.sol[[2]], {k, 1, n}]
  11. t1 = Table[Graphics3D[{Red, PointSize[0.02], Point[pts[[k]]]}], {k, 1, n}];
  12. e1 = Table[Graphics3D[{Red, Line[{pts[[i]], pts[[j]]}]}], {i, 1, n}, {j, 1, n}];
  13. t2 = Table[Graphics3D[{Blue, PointSize[0.02], Point[ptsol[[k]]]}], {k, 1, n}];
  14. e2 = Table[Graphics3D[{Blue, Line[{ptsol[[i]], ptsol[[j]]}]}], {i, 1, n}, {j, 1, n}];
  15. Show[e1, e2, t1, t2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement