function r = planar3rhsOctave(z,t) % % Defines the righthandside vector of the system of first-order % differential equations for the planar 3-body problem. % As the time t is second argument, this script is suitable for % the lsode command of Octave. % % ON INPUT : % z a vector with 12 entries, ordered in blocks of 4: % x[k](t), x'[k](t),y[k](t),y'[k](t), k = 1,2,3; % t value for the time parameter. % % ON RETURN : % r 12 values of the righthandside for the ODE. % % defining the three masses m = [1 0.5 0.2]; % m = [1 1 1]; r = zeros(1,12); % relabel input vector z x1 = z(1); u1 = z(2); y1 = z(3); v1 = z(4); x2 = z(5); u2 = z(6); y2 = z(7); v2 = z(8); x3 = z(9); u3 = z(10); y3 = z(11); v3 = z(12); % u and v are first derivatives of x and y r(1) = u1; r(3) = v1; r(5) = u2; r(7) = v2; r(9) = u3; r(11) = v3; % compute squared distances dx12 = x1 - x2; sdx12 = dx12^2; dx13 = x1 - x3; sdx13 = dx13^2; dx23 = x2 - x3; sdx23 = dx23^2; dy12 = y1 - y2; sdy12 = dy12^2; dy13 = y1 - y3; sdy13 = dy13^2; dy23 = y2 - y3; sdy23 = dy23^2; % denominators d12 = (sdx12 + sdy12)^(3/2); d13 = (sdx13 + sdy13)^(3/2); d23 = (sdx23 + sdy23)^(3/2); % righthandside for second order r(2) = - m(2)*dx12/d12 - m(3)*dx13/d13; r(4) = - m(2)*dy12/d12 - m(3)*dy13/d13; r(6) = - m(1)*(-dx12)/d12 - m(3)*dx23/d23; r(8) = - m(1)*(-dy12)/d12 - m(3)*dy23/d23; r(10) = - m(1)*(-dx13)/d13 - m(2)*(-dx23)/d23; r(12) = - m(1)*(-dy13)/d13 - m(2)*(-dy23)/d23;