Two-body problem program gone wrong

조회 수: 14 (최근 30일)
Matthew Lee
Matthew Lee 2021년 2월 24일
답변: edoardo de angeli 2021년 7월 30일
Hi everyone... I have written a simple program on matlab that will draw an orbit using ode45 to integrate the two body problem which is rddot = -mue.*rv/R^3
where:
rddot: second derivative of position vector (acceleration)
mue: Earth constant (which is known to be = 398600 km^3/s^2)
rv: position vector
R: position scalar
and my problem is the orbit will complete one circle without a problem but it will decay as it complete more than one period around the earth which I'm sure it's not the realistic case..
for example, completing one period it will look normal:
if I wanted to complete more than one period, the orbit will decay:
this picture is taken after completing 20 rotations.
someone please help if found any problem in my code or my mathematical expression,
this is my code:
r0=[-7072.7292 3150.61 123.8]'; %km
v0=[0.4600 -4.2446 -7.312]'; %km/s
y0=[r0;v0];
T=14332.25;
tspan=[0 T];
odefun=@dfdf;
[t,y]= ode45(odefun,tspan,y0);
xv = y(:,1);
yv = y(:,2);
zv = y(:,3);
plot3(xv,yv,zv)
axis equal
function [dydt]=dfdf(t,y)
rv=y(1:3);
R=norm(rv);
mue=398600.44189;
rdot=y(4:6);
rddot = -mue*rv/R^3;
dydt = [rdot;rddot];
end
  댓글 수: 1
Just Manuel
Just Manuel 2021년 2월 24일
More a philosophical answer, thus just as a comment:
In my experience, it is very hard to find parameters that produce a stable orbit. The fact that we are orbiting the sun is thus rather a miracle :) In fact, even the distance to the sun is growing (https://www.forbes.com/sites/startswithabang/2019/01/03/earth-is-drifting-away-from-the-sun-and-so-are-all-the-planets).
So I suspect that there is nothing wrong with your simulation. You just have not found the perfect parameter set. Try tweakind them a bit.
Cheers
Manuel

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2021년 2월 24일
Decrease the tolerance to reduce the truncation errors:
opt = odeset('AbsTol', 1e-8, 'RelTol', 1e-8);
[t,y]= ode45(odefun,tspan,y0, opt);
  댓글 수: 1
Matthew Lee
Matthew Lee 2021년 2월 24일
Thank you very much!!
that worked for me!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

darova
darova 2021년 2월 24일
rddot = -mue*rv/R^3;
This line tells that you have non-constant angular acceleration
So it's ok if you orbit is changing

edoardo de angeli
edoardo de angeli 2021년 7월 30일
How did you manage to iterate the process for more than one orbit?

카테고리

Help CenterFile Exchange에서 Gravitation, Cosmology & Astrophysics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by