Runge-kutta results do not align with ODE45 solver, what am I doing wrong?
Show older comments
I am working on simulation the movement of three bodies with mass M, position P, velocity V, acceleration A, and force applied in it F.
I am given the initial values of position and velocity to work with, and according to Newton laws I can acquire the force and the right hand side of equation
to implement Runge-Kutta and acquire the position of each body, though when I implement runge-kutta and compare the results to those I get from ODE45, I find them disimilar. What am I doing wrong?
I have attached the file of the instruction I was given and have followed.
The only two files that need to be run is ODE.m and testingrunge.m.
1 Comment
Just some hints for a simplification:
% Replace
P1=[X(1),X(2),X(3)];
% by
P1 = X(1:3);
% Replace
Y_matrix=cell2mat([{X(4),X(5),X(6)};
{A1(1),A1(2),A1(3)};
{X(10),X(11),X(12)};
{A2(1),A2(2),A2(3)};
{X(16),X(17),X(18)};
{A3(1),A3(2),A3(3)}]);
Y=(Y_matrix(:));
% by
Y = [X(4:6), A1, X(10:12), A2, X(16:18), A3].';
% Replace
F=((-1)*(M*M1).*(P-P1)/((norm(P-P1).^3)))-(1*M*M2.*(P-P2)./((norm(P-P2)).^3));
% by:
F= -M*M1 * (P-P1) / norm(P-P1).^3 - M*M2 * (P-P2) / (norm(P-P2).^3);
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!