- #1
patric44
- 308
- 40
- TL;DR Summary
- is it possible to Change value of variable at each time step?
hi guys
I am trying to implement the a second order differential equation tat contains a time dependent term, the equation looks something like
r'' = -\mu/r^3+(g/g^3-m/m^3)
the idea is that i want to calculate 'r' the position vector of a point, that is dependent on vectors g and m, I tired to crate an simple ode integrator to get the g vector as
than i tried to implement that in another function dx that will be integrated as
then this function is integrated using the ode45.
the thing is the values yk i don't know how to assign it to each time step that the integrator uses, is this the right thing to do it
I hope anybody help i tried to post this on mathwork but no answer
I am trying to implement the a second order differential equation tat contains a time dependent term, the equation looks something like
r'' = -\mu/r^3+(g/g^3-m/m^3)
the idea is that i want to calculate 'r' the position vector of a point, that is dependent on vectors g and m, I tired to crate an simple ode integrator to get the g vector as
Matlab:
function dx = themoonpos(t,x)
R = 6378.137;
u = 398600.441800; % km/s2
% J2 = 0.0010826269;
% b = -1.5*J2*u*R^2 ;
r = sqrt(x(1)^2+x(3)^2+x(5)^2);
%% the propagator
dx=[
x(2)
;-u*x(1)/(r)^3
;x(4)
;-u*x(3)/(r)^3
;x(6);
-u*x(5)/(r)^3];
end
than i tried to implement that in another function dx that will be integrated as
Matlab:
function dx = thethirdp(t,x,yk)
k0 = [
-120901.611171555;
89921.008706315/(24*60*60);
-298392.399263114;
-25049.485694581/(24*60*60);
-162652.182605121;
-12799.914191783/(24*60*60)
];
opts = odeset; opts.RelTol = 10^-9;
[t2,yk] = ode45(@themoonpos,[0:60:5000],k0,opts);
R = 6378.137;
u = 398600.432896939; % km/s2
um = 4902.80058214776; % km/s2
J2 = 0.0010826269;
b = -1.5*J2*u*R^2 ;
r = sqrt(x(1)^2+x(3)^2+x(5)^2);
xm = (yk(1)-x(1));
ym = (yk(3)-x(3));
zm = (yk(5)-x(5));
rd = sqrt(yk(1)^2+yk(3)^2+yk(5)^2);
rm = sqrt(xm^2+ym^2+zm^2);
%% the perturbation
apx = um*((xm/((rm))^3)-yk(1)/(rd)^3);
apy = um*((ym/((rm))^3)-yk(3)/(rd)^3);
apz = um*((zm/((rm))^3)-yk(5)/(rd)^3);
%% the Integrator
dx=[
x(2)
;-u*x(1)/(r)^3+apx
;x(4)
;-u*x(3)/(r)^3+apy
;x(6);
-u*x(5)/(r)^3+apz];
end
the thing is the values yk i don't know how to assign it to each time step that the integrator uses, is this the right thing to do it
I hope anybody help i tried to post this on mathwork but no answer