Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. MapQ = Compile[{{r0, _Real, 2}, {r, _Real, 2}, xc, yc, {w, _Real, 1}},
  2. Block[{ M = ({
  3. {0., 0., 0., 0.},
  4. {0., 0., 0., 0.},
  5. {0., 0., 0., 0.},
  6. {0., 0., 0., 0.}
  7. }), x0, y0, z0, x, y, z, w1, w2, r2, c1, c2, c3, c4, x0x, y0y,
  8. z0z, sys, [Theta], temp},
  9. Do[
  10. x0 = r0[[i, 1]] - xc; x = r[[i, 1]] - xc;
  11. y0 = r0[[i, 2]] - yc; y = r[[i, 2]] - yc;
  12. z0 = r0[[i, 3]]; z = r[[i, 3]];
  13.  
  14. (*// matrix elements//*)
  15. w1 = w[[i]];
  16. w2 = 2*w1;
  17. r2 = x^2 + y^2 + z^2 + x0^2 + y0^2 + z0^2;
  18. x0x = x0 x;
  19. y0y = y0 y;
  20. z0z = z0 z;
  21. c1 = (r2 - 2 (x0x + y0y + z0z));
  22. c2 = (r2 + 2 (-x0x + y0y + z0z));
  23. c3 = (r2 + 2 (x0x - y0y + z0z));
  24. c4 = (r2 + 2 (x0x + y0y - z0z));
  25. M[[1, 1]] += w1 c1;
  26. M[[1, 2]] += w2 (y z0 - z y0);
  27. M[[1, 3]] += w2 (-x z0 + z x0);
  28. M[[1, 4]] += w2 (x y0 - y x0);
  29. M[[2, 2]] += w1 c2;
  30. M[[2, 3]] -= w2 (x y0 + y x0);
  31. M[[2, 4]] -= w2 (x z0 + z x0);
  32. M[[3, 3]] += w1 c3;
  33. M[[3, 4]] -= w2 (y z0 + z y0);
  34. M[[4, 4]] += w1 c4;
  35.  
  36. , {i, Length[r0]}];
  37. M = ({
  38. {M[[1, 1]], M[[1, 2]], M[[1, 3]], M[[1, 4]]},
  39. {M[[1, 2]], M[[2, 2]], M[[2, 3]], M[[2, 4]]},
  40. {M[[1, 3]], M[[2, 3]], M[[3, 3]], M[[3, 4]]},
  41. {M[[1, 4]], M[[2, 4]], M[[3, 4]], M[[4, 4]]}
  42. })
  43.  
  44. ], RuntimeAttributes -> {Listable}, Parallelization -> True,
  45. CompilationTarget -> "C"];
  46.  
  47.  
  48.  
  49. AngleQ[M_] := Block[{sys, [Theta]},
  50. sys = Eigensystem[M];
  51. If[sys[[2, 4, 1]] < 0, sys[[2, 4]] = -sys[[2, 4]], None];
  52. sys[[2, 4]] = Normalize[sys[[2, 4]]];
  53. [Theta] = 2 ArcCos[sys[[2, 4, 1]]];
  54. If[sys[[2, 4, 4]]/Sin[[Theta]/2] < 0, [Theta] = -[Theta], None];
  55. [Theta]
  56. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement