Help me understand!

11 vues (au cours des 30 derniers jours)
Nour Butrus
Nour Butrus le 14 Fév 2022
Commenté : AndresVar le 16 Fév 2022
I am presented with a task of simulating the movement of three bodies with a constant mass using Newton's laws.
The task is very easy to follow and I have no trouble understanding it, until it comes to solving the differential equation using Runge-Kutta, where M is the mass of a body, is the second derivative of the position, namely, the acceleration and F is the force applied on M due to the two other masses.
Please refer to task number 3 below
Where equation 3 is I am finding it particularly difficult to understand why the right hand of the equation is a column consisten of what appears to be the velocity V for each body and the acceleration .
I would highly appreciate any guidance to the interpertation of the task!
  2 commentaires
Nour Butrus
Nour Butrus le 14 Fév 2022
Hey! Below are the tasks I am asked to solve, with the my code.
I am a 2nd year undergraduate student so I apologise that it is not perfect :)
Task 1
clc
clear all
%task #1
%Initial conditions
p=0.05;
P1=[0,0,0]; V1=[p,p,p];
P2=[1,0,0]; V2=[-p,p,p];
P3=[0,0,1]; V3=[-p,-p,-p];
V0=transpose([P1 V1 P2 V2 P3 V3]);
%Masses/Scalars M_i
M1=1; M2=2; M3=0.5;
Task 2
function F= Force(P,M,P1,M1,P2,M2)
F=((-1)*(M*M1).*(P-P1)/((norm(P-P1).^3)))-(1*M*M2.*(P-P2)./((norm(P-P2)).^3));
end
Task 3
function Y=RHS(t,X)
F1=Force(P1,M1,P2,M2,P3,M3);
F2=Force(P2,M2,P1,M1,P3,M3);
F3=Force(P3,M3,P1,M1,P2,M2);
Y=[{V1} {F1./M1} {V2} {F2./M2} {V3} {F3./M3}];
end

Connectez-vous pour commenter.

Réponse acceptée

AndresVar
AndresVar le 14 Fév 2022
Modifié(e) : AndresVar le 16 Fév 2022
Equation 3 is a 2nd order system p''=..., the RK3 is given for 1st order p'=...(see it's first difference ) =..)
See for example equation 14 here: part1.pdf (nyu.edu)
you can see how order is reduced by introducing firts time derivatives (V's) as new variables
  2 commentaires
AndresVar
AndresVar le 16 Fév 2022
f = Y = RHS(t,X). The RHS you commented above looks good just make sure P1=X(1), V1=X(2)... etc as defined in task#1. You didn't say, but I guess velocity is constant?
% at t0
Y0 = RHS(t0,X0)
% one step later Y(t0+h)=Y1
K1=h*Y0;
K2=h*RHS(t+h/2,Y0+h/2);
K3=...
Y1 = Y0 + 1/6(K1+4*K2+K3)
% two steps later Y(t0+2h)=Y2
K1=h*Y1;
K2=...
K3=...
Y2 = Y1 + 1/6(K1+4*K2+K3)
code repeats, so just turn it into a loop for N steps
h = 0.01;
t(1) = 0;
Y(1)=RHS(t0,X0) %initial
for ii = 1:N
t(ii+1) = t(ii)+h
K1 =...
K2 =...
K3 =...
Y(ii+1) = Y(ii)+1/6(K1+4*K2+K3);
end
plot the forces vs time to see if they behave nicely... if not then you can play with the step size h

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by