PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/utils/t2r.m

http://slac-lucretia.googlecode.com/
MATLAB | 55 lines | 29 code | 5 blank | 21 comment | 2 complexity | efa4fd5a8999c3b66a5e6a9398fff3b9 MD5 | raw file
Possible License(s): BSD-2-Clause
  1. function R=t2r(E1,P1,E2,P2,mu)
  2. %
  3. % Compute pseudo-4x4 R-matrix (diagonal 2x2's) between two points from
  4. % twiss parameters.
  5. %
  6. % (NOTE: Pn=[psix,betax,alphax,etax,etapx,psiy,betay,alphay,etay,etapy])
  7. %
  8. % INPUTs:
  9. %
  10. % E1 = energy at point 1 (GeV)
  11. % P1 = twiss at point 1
  12. % E2 = energy at point 2 (GeV)
  13. % P2 = twiss at point 2
  14. % mu = (optional) if provided and nonzero, convert phases in tune units
  15. % to radians
  16. %
  17. % OUTPUT:
  18. %
  19. % R=[R11 R12 0 0
  20. % R21 R22 0 0
  21. % 0 0 R33 R34
  22. % 0 0 R43 R44]
  23. if (nargin<5)
  24. mu=0;
  25. end
  26. if (mu)
  27. conv=2*pi;
  28. else
  29. conv=1;
  30. end
  31. R=eye(4);
  32. psi1=conv*P1(1);beta1=P1(2);alpha1=P1(3);
  33. psi2=conv*P2(1);beta2=P2(2);alpha2=P2(3);
  34. dpsi=psi2-psi1;
  35. S=sin(dpsi);
  36. C=cos(dpsi);
  37. R(1,1)=sqrt(beta2/beta1)*(C+alpha1*S);
  38. R(1,2)=sqrt(beta1*beta2)*S;
  39. R(2,1)=-((1+alpha1*alpha2)*S+(alpha2-alpha1)*C)/sqrt(beta1*beta2);
  40. R(2,2)=sqrt(beta1/beta2)*(C-alpha2*S);
  41. psi1=conv*P1(6);beta1=P1(7);alpha1=P1(8);
  42. psi2=conv*P2(6);beta2=P2(7);alpha2=P2(8);
  43. dpsi=psi2-psi1;
  44. S=sin(dpsi);
  45. C=cos(dpsi);
  46. R(3,3)=sqrt(beta2/beta1)*(C+alpha1*S);
  47. R(3,4)=sqrt(beta1*beta2)*S;
  48. R(4,3)=-((1+alpha1*alpha2)*S+(alpha2-alpha1)*C)/sqrt(beta1*beta2);
  49. R(4,4)=sqrt(beta1/beta2)*(C-alpha2*S);
  50. R=sqrt(E1/E2)*R;