Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = 5;
- pts = RandomReal[{-10, 10}, {n, 3}]
- DD = Table[(pts[[i]] - pts[[j]]).(pts[[i]] - pts[[j]]), {i, 1, n}, {j, 1, n}]
- For[i = 1; s = 0, i <= n, i++,
- 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]
- ]
- ]
- vars = Variables[s]
- sol = Minimize[s, vars]
- ptsol = Table[{Subscript[x, k], Subscript[y, k], Subscript[z, k]} /.sol[[2]], {k, 1, n}]
- t1 = Table[Graphics3D[{Red, PointSize[0.02], Point[pts[[k]]]}], {k, 1, n}];
- e1 = Table[Graphics3D[{Red, Line[{pts[[i]], pts[[j]]}]}], {i, 1, n}, {j, 1, n}];
- t2 = Table[Graphics3D[{Blue, PointSize[0.02], Point[ptsol[[k]]]}], {k, 1, n}];
- e2 = Table[Graphics3D[{Blue, Line[{ptsol[[i]], ptsol[[j]]}]}], {i, 1, n}, {j, 1, n}];
- Show[e1, e2, t1, t2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement