SHARE
TWEET

turdicus rex

a guest Apr 23rd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function out = Lambert(rbar1,rbar2,TOF,tm,mu)
  2.     r1 = norm(rbar1);
  3.     r2 = norm(rbar2);
  4.     TOFn = 0;
  5.     delV = acos(dot(rbar1,rbar2)/(r1*r2));
  6.     A = tm*sqrt(r1*r2*(1+cos(delV)));
  7.    
  8.     if A == 0
  9.         out = [0,0];
  10.     else
  11.         z = 0;
  12.         C = 1/2;
  13.         S = 1/6;
  14.         zUp = 4*pi^2;
  15.         zLow =-4*pi;
  16.        
  17.         while (abs(TOFn - TOF) > 1*10^(-6))
  18.             yn = r1+r2+A*(z*S-1)/sqrt(C);
  19.             xn = sqrt(yn/C);
  20.             TOFn = (xn^3*S+A*sqrt(yn))/sqrt(mu);
  21.             if (TOFn <= TOF)
  22.                 zLow = z;
  23.             else
  24.                 zUp = z;
  25.             end
  26.             z = (zUp+zLow)/2;
  27.             if (z > 1*10^(-6))
  28.                 C = (1-cos(sqrt(z)))/z;
  29.                 S =(sqrt(z)-sin(sqrt(z)))/sqrt(z^3);
  30.             elseif (z < -1*10^(-6))
  31.                 C = (1-cosh(sqrt(-z)))/z;
  32.                 S = (sinh(sqrt(-z))-sqrt(-z))/sqrt((-z)^3);
  33.             else
  34.                 C = 1/2;
  35.                 S = 1/6;
  36.             end
  37.         end
  38.         f = 1-yn/r1;
  39.         gdot = 1 - yn/r2;
  40.         g = A*sqrt(yn/mu);
  41.         v1 = (rbar2 - f*rbar1)/g;
  42.         v2 = (gdot*rbar2 - rbar1)/g;
  43.         out = [v1',v2'];
  44.     end
  45. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top