function dYdt = Apollo2Dfunc(t,Y)

global mEarth mMoon mSatellite mRocket G

rm = [Y(1);Y(2)];
vm = [Y(3);Y(4)];

re = [Y(5);Y(6)];
ve = [Y(7);Y(8)];

rs = [Y(9);Y(10)];
vs = [Y(11);Y(12)];

rr = [Y(13);Y(14)];
vr = [Y(15); Y(16)];



dem = sqrt((rm(1)-re(1))^2 + (rm(2)-re(2))^2);
dsm = sqrt((rs(1)-rm(1))^2 + (rs(2)-rm(2))^2);
dse = sqrt((rs(1)-re(1))^2 + (rs(2)-re(2))^2);
dre = sqrt((rr(1)-re(1))^2 + (rr(2)-re(2))^2);
drm = sqrt((rr(1)-rm(1))^2 + (rr(2)-rm(2))^2);

Fme = - mEarth * mMoon * G / dem^3 .* (rm-re);
Fem = - mEarth * mMoon * G / dem^3 .* (re-rm);
Fsm = - mMoon * mSatellite * G / dsm ^3 .* (rs-rm);
Fse = - mEarth * mSatellite * G / dse ^3 .* (rs-re);
Fre = - mEarth * mSatellite * G / dre ^3 .* (rr-re);
Frm = - mMoon * mSatellite * G / drm ^3 .* (rr-rm);


amx = Fme(1) / mMoon;
amy = Fme(2) / mMoon;

aex =  Fem(1) / mEarth;
aey =  Fem(2) / mEarth;


asx = ((Fse(1)+Fsm(1))/ mSatellite);
asy = ((Fse(2)+Fsm(2))/ mSatellite);

arx = ((Frm(1) + Fre(1))/ mRocket);
ary = ((Frm(2) + Fre(2))/ mRocket);

dYdt = [ vm(1) ; vm(2) ; amx ; amy; ve(1); ve(2); aex; aey; vs(1); vs(2); asx; asy; vr(1); vr(2); arx; ary ];   

