How to solve for multiple 'objects' in single ode function

1 Ansicht (letzte 30 Tage)
Robin Szabo
Robin Szabo am 27 Mär. 2019
Kommentiert: Robin Szabo am 27 Mär. 2019
Hi,
So I am trying to model the solar system by using ODE45 however I have run into an issue. Due to later concerns I'm trying to make the whole system dynamic and make it so that the planets interact with each other. I have a set of initial coordinates I have calculated for each of the planets, and I have calculated the distance between the planets and the sun for each of the planets I have. The next part I wanted to calculate was the acceleration for each of the planets however I have run into a problem I am not entirely clear on how to solve. The ODE wants the output value to be a column vector however this seems like a massive issue as having 4 parameters (at least if not more) on a single column for 8 planets would make the list very long. Currently it creates a matrix but this will only run the ODE once and it fails with an error.
I have not included the importing of the initial values as they are in spreadsheets I imported and don't believe it is relevant
Thanks
%% Planet motion
G = 6.67e-11; %Gravitational Constant
u = G*planetStart(1,6); %Gravitational Constant multiplied by sun mass
res = 1; %The resolution the code should run at in days
last = 365; %The number of days the code should run for (from 1/1/19)
tSpan = 0:res:last;
[t,x] = ode45(@(t,x) pos(planetsXY,planetsVel,planetsMass,u),tSpan,planetsXY);
planetsX = x(:,1); %Planets x coordinates
planetsY = x(:,2); %Planets y coordinates
planetsRad = x(:,3); %Distance between planets and sun
planetsAcc = x(:,4); %Acceleration of each planet
function ode45 = pos(planetsXY,planetsVel,planetsMass,u)
ode45 = [0 0 0 0]'; %Transposed matrix of initial values
for i = 1:9
ode45(i,3) = abs(norm(planetsXY(i,:)));
ode45(i,4) = u/ode45(i,3)^2
end
end

Antworten (1)

Walter Roberson
Walter Roberson am 27 Mär. 2019
You can reshape the boundary values into a matrix to work with them and you can create your results in a matras long as you reshape to a vector just before you return.
  1 Kommentar
Robin Szabo
Robin Szabo am 27 Mär. 2019
So the issue with this is that it will create a very long column of numbers (upwards of at least 20 until more items are added, then even more) is there no way around this?
If not what is a good method to merge a matrix into a column then organise that into different values after?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Earth and Planetary Science finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by