求解轨道力学二体意义下的Lambert方程(兰伯特方程)的Matlab程序

轨道力学中二体问题下求解兰伯特方程需要解决一个迭代问题。

这是一个老外写的,有很多注释,相信大家应该能看懂,经实际检测,切实可用


function [v1,v2]=solve_lambert(r1,r2,t,GM,lw,N,branch)
%This routine implements a new algorithm that solves Lambert‘s problem. The
%algorithm has two major characteristics that makes it favorable to other
%existing ones.
%
% 1) It describes the generic orbit solution of the boundary condition
% problem through the variable X=log(1+cos(alpha/2)). By doing so the
% graphs of the time of flight become defined in the entire real axis and
% resembles a straight line. Convergence is granted within few iterations
% for all the possible geometries (except, of course, when the transfer
% angle is zero). When multiple revolutions are considered the variable is
% X=tan(cos(alpha/2)*pi/2).
%
% 2) Once the orbit has been determined in the plane, this routine
% evaluates the velocity vectors at the two points in a way that is not
% singular for the transfer angle approaching to pi (Lagrange coefficient
% based methods are numerically not well suited for this purpose).
%
% As a result Lambert‘s problem is solved (with multiple revolutions
% being accounted for) with the same computational effort for all
% possible geometries. The case of near 180 transfers is also solved
% efficiently.
%
% We note here that even when the transfer angle is exactly equal to pi
% the algorithm does solve the problem in the plane (it finds X), but it
% is not able to evaluate the plane in which the orbit lies. A solution
% to this would be to provide the direction of the plane containing the
% transfer orbit from outside. This has not been implemented in this
% routine since such a direction would depend on which application the
% transfer is going to be used in.
%
%Usage: [v1,v2,a,p,theta,iter]=solve_lambert(r1,r2,t,GM,lw,N,branch)
%
%Inputs:
% r1=Position vector at departure (column,km)
% r2=Position vector at arrival (column, same units as r1,km)
% t=Transfer time (scalar,s)
% GM=gravitational parameter (scalar, units have to be
% consistent with r1,t units,km^3/s^2)
% lw=1 if long way is chosen
% branch=1 if the left branch is selected in a problem where N
% is not 0 (multirevolution)
% 注:天体运行是右分支.所以branch一般选择0
% N=number of revolutions
%
% 说明:当N~=0时,旋转方向不光用lw来控制还要先用branch来控制.
%Outputs:
% v1=Velocity at departure (consistent units)(km/s)
% v2=Velocity at arrival (km/s)

% iter=number of iteration made by the newton solver (usually 6)
%
% 当需要时可以加上.
%补充说明:
% [v1,v2,a,p,theta,iter]=lambertI(r1,r2,t,GM,lw,N,branch);

%branch=1;%here 1 is represent left
%Preliminary control on the function call

if t<=0
disp(‘Negative time as input‘);
v1=NaN;
v2=NaN;
return
end

tol=1e-11; %Increasing the tolerance does not bring any advantage as the
%precision is usually greater anyway (due to the rectification of the tof
%graph) except near particular cases such as parabolas in which cases a
%lower precision allow for usual convergence.

%Non dimensional units
R=sqrt(r1‘*r1);
V=sqrt(GM/R);
T=R/V;

%working with non-dimensional radii and time-of-flight
r1=r1/R;
r2=r2/R;
t=t/T;

%Evaluation of the relevant geometry parameters in non dimensional units
r2mod=sqrt(r2‘*r2);
theta=real(acos((r1‘*r2)/r2mod)); %the real command is useful when theta is very
%close to pi and the acos function could return complex numbers

%计算夹角,并确定是大弧还是小弧.
if lw
theta=2*pi-theta;
end
c=sqrt(1+r2mod^2-2*r2mod*cos(theta)); %non dimensional chord
s=(1+r2mod+c)/2; %non dimensional semi-perimeter
am=s/2; %minimum energy ellipse semi major axis
lambda=sqrt(r2mod)*cos(theta/2)/s; %lambda parameter defined in BATTIN‘s book

%We start finding the log(x+1) value of the solution conic:
%%NO MULTI REV --> (1 SOL)
if N==0
inn1=-.5233; %first guess point
inn2=.5233; %second guess point
x1=log(1+inn1);
x2=log(1+inn2);
y1=log(x2tof(inn1,s,c,lw,N))-log(t);
y2=log(x2tof(inn2,s,c,lw,N))-log(t);

%Newton iterations
err=1;
i=0;
while (err>tol) && (y1~=y2)
i=i+1;
xnew=(x1*y2-y1*x2)/(y2-y1);
ynew=log(x2tof(exp(xnew)-1,s,c,lw,N))-log(t);
x1=x2;
y1=y2;
x2=xnew;
y2=ynew;
err=abs(x1-xnew);
end
x=exp(xnew)-1;

%%MULTI REV --> (2 SOL) SEPARATING RIGHT AND LEFT BRANCH
else
if branch==1
inn1=-.5234;
inn2=-.2234;
else
inn1=0.2;
inn2=.5234;
end
x1=tan(inn1*pi/2);
x2=tan(inn2*pi/2);
y1=x2tof(inn1,s,c,lw,N)-t;

y2=x2tof(inn2,s,c,lw,N)-t;
err=1;
i=0;

%Newton Iteration
while ((err>tol) && (i<90) && (y1~=y2))
i=i+1;
xnew=(x1*y2-y1*x2)/(y2-y1);
ynew=x2tof(atan(xnew)*2/pi,s,c,lw,N)-t;
x1=x2;
y1=y2;
x2=xnew;
y2=ynew;
err=abs(x1-xnew);
end
x=atan(xnew)*2/pi;
end

%The solution has been evaluated in terms of log(x+1) or tan(x*pi/2), we
%now need the conic. As for transfer angles near to pi the lagrange
%coefficient technique goes singular (dg approaches a zero/zero that is
%numerically bad) we here use a different technique for those cases. When
%the transfer angle is exactly equal to pi, then the ih unit vector is not
%determined. The remaining equations, though, are still valid.

a=am/(1-x^2); %solution semimajor axis
%calcolo psi
if x<1 %ellisse
beta=2*asin(sqrt((s-c)/2/a));
if lw
beta=-beta;
end
alfa=2*acos(x);
psi=(alfa-beta)/2;
eta2=2*a*sin(psi)^2/s;
eta=sqrt(eta2);
else %iperbole
beta=2*asinh(sqrt((c-s)/2/a));
if lw
beta=-beta;
end
alfa=2*acosh(x);
psi=(alfa-beta)/2;
eta2=-2*a*sinh(psi)^2/s;
eta=sqrt(eta2);
end
p=r2mod/am/eta2*sin(theta/2)^2; %parameter of the solution
sigma1=1/eta/sqrt(am)*(2*lambda*am-(lambda+x*eta));
ih=cross(r1,r2)/norm(cross(r1,r2));
if lw
ih=-ih;
end

vr1 = sigma1;
vt1 = sqrt(p);
v1 = vr1 * r1 + vt1 * cross(ih,r1);

vt2=vt1/r2mod;
vr2=-vr1+(vt1-vt2)/tan(theta/2);
v2=vr2*r2/r2mod+vt2*cross(ih,r2/r2mod);

v1=v1*V;
v2=v2*V;
if err>tol
v1=[100 100 100]‘;
v2=[100 100 100]‘;
end

function t=x2tof(x,s,c,lw,N)
%Subfunction that evaluates the time of flight as a function of x
am=s/2;
a=am/(1-x^2);
if x<1 %ELLISSE
beta=2*asin(sqrt((s-c)/2/a));
if lw
beta=-beta;
end
alfa=2*acos(x);
else %IPERBOLE
alfa=2*acosh(x);
beta=2*asinh(sqrt((s-c)/(-2*a)));
if lw
beta=-beta;
end
end
t=tofabn(a,alfa,beta,N);

function t=tofabn(sigma,alfa,beta,N)
%subfunction that evaluates the time of flight via Lagrange expression
if sigma>0
t=sigma*sqrt(sigma)*((alfa-sin(alfa))-(beta-sin(beta))+N*2*pi);
else
t=-sigma*sqrt(-sigma)*((sinh(alfa)-alfa)-(sinh(beta)-beta));
end

求解轨道力学二体意义下的Lambert方程(兰伯特方程)的Matlab程序,布布扣,bubuko.com

时间: 2024-10-10 17:31:52

求解轨道力学二体意义下的Lambert方程(兰伯特方程)的Matlab程序的相关文章

我写了一个 二体 模拟程序, 大伙来看看吧

项目地址 :            https://github.com/kelin-xycs/Two-Body    , 项目只有一个 文件   TwoBody.html ,   用 浏览器 打开 就可以 运行 了 .    用 Html 5 + javascript 写的, 现在的 浏览器 应该都可以运行  . 大家可以 修改 参数 试试 不同参数 下 的 二体 运动状况,      比如  两个 质点 的 初始位置,  初始速度,  质量,  万有引力常量 等等  . 可以发现,    二

力学知识点提要(下)

力学知识点提要(下) 版本:2019-07-07 此版本并非最终版本,后续还会有知识的补充和更新. 如有错误请指出,转载时请注明出处! page21 page22 page23 page24 page25 page26 page27 page28 page29 Copyright ©2019 阆苑祁寒 更多内容,敬请期待:力学思考题选解(二) 原文地址:https://www.cnblogs.com/sxwlttsd/p/11145904.html

浅谈模质数意义下的乘法逆元

原文链接(更好的阅读体验) 参考文章www.luogu.org/blog/zyxxs/post-xiao-yi-jiang-tan-qian-tan-sheng-fa-ni-yuan 什么是乘法逆元 若整数\(b,m\)互质,并且\(b|a\),若存在一个整数\(x\),使得\(a / b \equiv a \ast x (mod \text{ } m)\),称\(x\)为 \(b\)的模\(m\)乘法逆元. 乘法逆元的用处 有时候,我们需要求\(a/b \text{ } mod \text{

第十二章课下测试补交博客

第十二章课下测试补交博客

模意义下的组合数

模意义下的组合数 求\(C_{n}^{k}\%p\)(p为质数) \[C_{n}^{k}=\frac{n!}{k!(n-k)!}\] 设\(n!=a_1p^{e_1}, k!=a_2p^{e_2}, (n-k)!=a_3p^{e_3}\) 如果\(e_1-(e_2+e_3)>0\),则\(C_{n}^{k}\%p=0\) 否则\(C_{n}^{k}\%p=\frac{a_1}{a_2a_3}\%p=a_1(a_2a_3)^{(p-2)}\%p\)(费马小定理) LL mod_fact(LL n,

不超过 $10^{18}$ 的非负整数在模意义下的乘法

约定:在博主的校内 OJ 上, long double  类型支持阶码 $15$ 位.有效值 $63$ 位(即科学记数法保留 $64$ 位有效数字).以下讨论以此为前提. 设非负整数 $a, b, p$ 满足 $a, b<p<2^{63},\ p \ne 0,$ 求 $ab \bmod p.$ $$ab \bmod p=ab-p\left\lfloor {ab \over p} \right\rfloor$$ 我们知道 $\left\lfloor {ab \over p} \right\rfl

Spring学习(二)——使用用Gradle构建一个简单的Spring MVC Web应用程序

1.新建一个Gradle工程(Project) 在新建工程窗口的左侧中选择 [Gradle],右侧保持默认选择,点击next,模块命名为VelocityDemo. 2.在该工程下新建一个 module,在弹出的窗口的左侧中选择 [Gradle],右侧勾选[Spring MVC],如下图所示: 并勾选[Application server],下方选择框中选择Tomcat7.0,如无该选项,则选中右边的 [ New... ] -- [ Tomcat Server ], 配置 Tomcat .配置好后

二值法方法综述及matlab程序

在某些图像处理当中一个关键步是二值法,二值化一方面能够去除冗余信息,另一方面也会使有效信息丢失.所以有效的二值化算法是后续的处理的基础.比如对于想要最大限度的保留下面图的中文字,以便后续的定位处理. 二值化算法包括全局二值化和局部二值化, 全局二值化具有速度快但效果相对差的特点, 局部二值化算法具有速度慢效果好的特点. 原图 全局阈值              方法一:直接采用im2bw ;手动阈值 方法二:迭代法求阈值 迭代式阈值选取的基本思路是:首先根据图像中物体的灰度分布情况,选取一个近似

Linux下adb驱动问题Linux下使用手机USB调试模式连接ADB进行Android程序的调试

Linux 下adb 驱动问题 Linux下使用手机USB调试模式连接ADB进行Android程序的调试,配置驱动没有Windows来的直观. 具体步骤首先确认手机连接上电脑,lsusb查看下设备记录. [email protected]:~$ lsusb Bus 007 Device 009: ID 18d1:4e12 Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 006 Device 001: ID 1d