Skip to content

Instantly share code, notes, and snippets.

@uliludmann
Created December 19, 2018 13:49
Show Gist options
  • Save uliludmann/1abcd60c2669fc4bea67d3c510944f03 to your computer and use it in GitHub Desktop.
Save uliludmann/1abcd60c2669fc4bea67d3c510944f03 to your computer and use it in GitHub Desktop.
function [drdt] = f_PlanSim_Multibody(t, r, G, m)
%% Init der Variablen:
r_in = r(1:length(r)/2); %Transpose vector input
v_in = r(length(r)/2 + 1:end); %velocity vector input
distances = squareform(pdist(r_in)); %euclidean distances of the n bodies as square matrix.
a = G * ( m / distances^2 ); %% matrix form of gravitational
a = a(a~=0 & isfinite(a)); %% remove infinity values
a_ges = sum(a, 2);
% Finaler Ausgabevektor:
drdt = [v_in a_ges]'; %eigentlich geschwindigkeit und beschleunigung aber nach integration ortsvektor und geschwindigkeitsvektor
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment