function dYdt = rogueplanet_ode(t,Y)

rs = [Y(1),Y(2)];           %Initial position / velocity of all objects from Y vector defined in rogueplanet.m
vs = [Y(3),Y(4)];
rmerc = [Y(5),Y(6)];
vmerc = [Y(7),Y(8)];
rv = [Y(9),Y(10)];
vv = [Y(11),Y(12)];
re = [Y(13),Y(14)];
ve = [Y(15),Y(16)];
rmars = [Y(17),Y(18)];
vmars=[Y(19),Y(20)];
rjup = [Y(21),Y(22)];
vjup = [Y(23),Y(24)];
rj = [Y(25),Y(26)];
vj = [Y(27),Y(28)];
rp = [Y(29),Y(30)];
vp = [Y(31),Y(32)];

global ms mmerc mv G me mmars mj mjup mp

FSMERC = -(ms * mmerc * G) / (norm(rs-rmerc))^3 *(rs-rmerc);       %Calculating all forces on the Sun
FSV = -(ms * mv * G) / (norm(rs-rv))^3 *(rs-rv);
FSE = -(ms * me * G) / (norm(rs-re))^3 *(rs-re);
FSMARS = -(ms * mmars * G) / (norm(rs - rmars))^3 *(rs-rmars);
FSJUP = -(ms * mjup * G) / (norm(rs - rjup))^3 *(rs - rjup);
FSJ = -(mj * ms * G) / (norm(rs-rj))^3 * (rs-rj);
FSP = -(ms *mp * G) / (norm(rs-rp))^3 *(rs-rp);

FES = -(ms * me * G) / (norm(re-rs))^3 *(re-rs);                    %Calculating all forces on the Earth
FEMERC = -(me * mmerc * G) / (norm(re-rmerc))^3 *(re-rmerc);
FEV = -(me * mv * G) / (norm(re-rv))^3 *(re-rv);
FEMARS = -(me * mmars * G) / (norm(re-rmars))^3 *(re-rmars);
FEJUP = -(me *mjup *G) / (norm(re-rjup))^3 * (re-rjup);
FEJ = -(mj * me * G) / (norm(re - rj))^3 * (re-rj);
FEP = -(mp * me * G) / (norm(re-rp))^3 * (re-rp);

FMERCS = -(ms * mmerc * G) / (norm(rmerc-rs))^3 *(rmerc-rs);       %Calculating all forces on Mercury
FMERCV = -(mmerc * mv * G) / (norm(rmerc-rv))^3 *(rmerc-rv);
FMERCE = -(mmerc * me * G) / (norm(rmerc-re))^3 *(rmerc-re);
FMERCMARS = -(mmerc * mmars * G) / (norm(rmerc-rmars)^3) *(rmerc-rmars);
FMERCJUP = -(mmerc *mjup * G) / (norm(rmerc-rjup))^3 * (rmerc - rjup);
FMERCJ = -(mj * mmerc * G) / (norm(rmerc - rj))^3 * (rmerc - rj);
FMERCP = -(mmerc * mp * G) / (norm(rmerc-rp))^3 * (rmerc -rp);

FVS = -(ms * mv * G) / (norm(rv-rs))^3 *(rv-rs);                  %Calculating all forces on Venus
FVMERC = -(mv * mmerc * G) / (norm(rv-rmerc))^3 *(rv-rmerc);
FVE = -(me * mv * G) / (norm(rv-re))^3 *(rv-re);
FVMARS = -(mv * mmars * G) / (norm(rv-rmars)^3) * (rv-rmars);
FVJUP = -(mv * mjup * G) / (norm(rv -rjup))^3 *(rv-rjup);
FVJ = -(mj * mv * G) / (norm(rv-rj))^3 * (rv-rj);
FVP = -(mv * mp *G) / (norm(rv-rp))^3 *(rv-rp);

FMARSS = -(mmars * ms * G) / (norm(rmars-rs)^3) * (rmars-rs);             %Calculating all forces on Mars
FMARSMERC = -(mmars * mmerc * G) / (norm(rmars-rmerc)^3) * (rmars-rmerc);
FMARSV = -(mmars * mv * G) / (norm(rmars-rv)^3) * (rmars-rv);
FMARSE = -(mmars * me * G) / (norm(rmars-re)^3) * (rmars-re);
FMARSJUP = -(mmars * mjup * G) / (norm(rmars-rjup))^3 *(rmars-rjup);
FMARSJ = -(mmars * mj * G) / (norm(rmars - rj))^3 * (rmars-rj);
FMARSP = -(mmars * mp * G) / (norm(rmars - rp))^3 * (rmars-rp);

FJS = -(ms * mj * G) / (norm(rj-rs))^3 *(rj-rs);                %Calculating all forces on rogue planet #1
FJMERC = -(mmerc * mj * G) / (norm(rj-rmerc))^3 *(rj-rmerc);
FJV = -(mv * mj * G) / (norm(rj-rv))^3 *(rj-rv);
FJE = -(me * mj * G) / (norm(rj-re))^3 *(rj-re);
FJMARS = -(mj * mmars * G) / (norm(rj-rmars))^3 * (rj - rmars);
FJJUP = -(mj * mjup * G) / (norm(rj-rjup))^3 *(rj-rjup);
FJP = -(mj * mp * G) / (norm(rj-rp))^3 * (rj-rp);

FJUPS = -(mjup* ms* G) / (norm(rjup-rs))^3 * (rjup-rs);             %Calculating all forces on Jupiter
FJUPMERC = -(mjup* mmerc* G) / (norm(rjup-rmerc))^3 * (rjup-rmerc);
FJUPV = -(mjup* mv* G) / (norm(rjup-rv))^3 * (rjup-rv);
FJUPE = -(mjup* me* G) / (norm(rjup-re))^3 * (rjup-re);
FJUPMARS = -(mjup* mmars* G) / (norm(rjup-rmars))^3 * (rjup-rmars);
FJUPJ = -(mjup* mj* G) / (norm(rjup-rj))^3 * (rjup-rj);
FJUPP = -(mjup * mp * G) / (norm(rjup-rp))^3 *(rjup-rp);

FPS = -(ms * mp * G) / (norm(rp-rs))^3 * (rp-rs);              %Calculating all forces on rogue planet #2
FPMERC = -(mmerc * mp * G) / (norm(rp-rmerc))^3 * (rp-rmerc);
FPV = -(mv * mp * G) / (norm(rp-rv))^3 * (rp-rv);
FPE = -(me * mp * G) / (norm(rp-re))^3 * (rp-re);
FPMARS = -(mmars * mp * G) / (norm(rp-rmars))^3 * (rp-rmars);
FPJUP = -(mjup * mp * G) / (norm(rp-rjup))^3 * (rp-rjup);
FPJ = -(mj * mp * G) / (norm(rp-rj))^3 * (rp-rj);



as = (FSE + FSMERC + FSMARS + FSV + FSJ + FSJUP + FSP) / ms;                          %calculates acceleration of all objects
amerc = (FMERCS + FMERCV + FMERCE + FMERCMARS + FMERCJ + FMERCJUP +FMERCP) / mmerc;
av = (FVS + FVMERC + FVE + FVMARS + FVJ + FVJUP + FVP) / mv;
ae = (FES + FEMERC + FEV + FEMARS + FEJ + FEJUP +FEP) / me;
amars = (FMARSS + FMARSMERC + FMARSV + FMARSE + FMARSJ + FMARSJUP +FMARSP) / mmars;
aj = (FJS + FJMERC + FJV + FJE + FJMARS + FJJUP +FJP) / mj;
ajup = (FJUPS + FJUPMERC + FJUPV + FJUPE + FJUPMARS + FJUPJ +FJUPP) / mjup;
ap = (FPS + FPMERC + FPV + FPE + FPMARS + FPJUP + FPJ) / mp;

dYdt = [vs(1); vs(2); as(1); as(2); vmerc(1); vmerc(2); amerc(1); amerc(2); vv(1); vv(2); av(1); av(2); ve(1); ve(2); ae(1); ae(2); vmars(1); vmars(2); amars(1); amars(2); vjup(1); vjup(2); ajup(1); ajup(2) ; vj(1) ; vj(2) ; aj(1) ; aj(2); vp(1); vp(2); ap(1); ap(2)];