%Script file to run the three body simulator clear %Get the initial conditions: % The vector w is partioned as: % w(1,2)=(x1,y1) Position of body 1 % w(3,4)=(x2,y2) Position of body 2 % w(5,6)=(x3,y3) Position of body 3 % w(7,8)=(dx1,dy1) Velocity of body 1 % w(9,10)=(dx2,dy2) Velocity of body 2 % w(11,12)=(dx3,dy3) Velocity of body 3 t1=0;t2=pi/3;t3=2*pi/3; winit=[cos(t1),sin(t1),cos(t2),sin(t2),cos(t3),sin(t3),... -sin(t1),cos(t1),-sin(t2),cos(t2),-sin(t3),cos(t3)]; %winit=[0,0.1,10,0,-10,0,0,0,0,0.5,0,-1]; %Explanation of the next function call: The first % input won't change- it's the m-file that computes % the derivatives. The next input is defining the % time values that you want the solution to be evaluated % at. Alternatives for this input are: % [ timestart, timeend ] like: [0,100] % or [ timestart : skip value : timeend] like: [0:0.2:100] % The last argument is the initial condition. [t,w]=ode45('threebody',[0,50],winit); plot(w(:,1),w(:,2),w(:,3),w(:,4),w(:,5),w(:,6))