% Simulation % By: Jay Borthen % A two point-mass gravitational system clear all close all % Fun Fact - The Earth supposedly has a mass of 5.9736x10^24 kg M1=550000000; % kg M2=125000000; % kg G=6.67384*10^(-11); %N*(m/kg)^2 P_M1=[23 20]; % Initial point in space of mass 1 V_M1=[0.05 0.03]; % Initial velocity vector of mass 1 P_M2=[10 15]; % Initial point in space of mass 2 V_M2=[-0.02 0.1]; % Initial velocity vector of mass 2 for t=1:1000 % seconds rVec=P_M2-P_M1; plot(P_M1(1),P_M1(2),'b.') hold on plot(P_M2(1),P_M2(2),'r.') axis([-5 50 -5 50]) hold on r=sqrt((rVec(1)^2)+(rVec(2)^2)); F=G.*(M1.*M2)/(r.^2); F1=F.*rVec; F2=-F.*rVec; V_M1=V_M1+(F1/M1); P_M1=P_M1+(V_M1)/2; V_M2=V_M2+(F2/M2); P_M2=P_M2+(V_M2)/2; grid on pause(0.05) end