Error in ode45
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
christian fares
am 18 Mai 2020
Bearbeitet: Walter Roberson
am 29 Jul. 2021
I added to a code another planet and when i added the Mercury planet on ode45 i got an error that is:
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in SimpleGravity (line 39)
[attime,finalposition]=ode45(@Propagator,[0:stepsize:finaltime],[EarthInitial]);
%% Inputs
stepsize=1; %step size in days, should not exceed 1
finaltime=10; %days from t0
%% System Conditions
global sunm G
sunm=1.9891e30; %kg
G=1.4879*10^(-34); %AU^3/(kg*Day^2)
%% Earth Initial Conditions
x=-7.829690890802676E-01; %AU
y=6.009223815219861E-01; %AU
z=-1.377986550047871E-05; %AU
Vx=-1.075646922487205E-02;%AU/day
Vy=-1.370584048238274E-02;%AU/day
Vz=3.974096024543801E-08; %AU/day
EarthInitial=[x,y,z,Vx,Vy,Vz]; %summary of initial conditions of the earth
%% New planet
Mx=-2.829690890802676E-01; %AU
My=8.009223815219861E-01; %AU
Mz=-4.377986550047871E-05; %AU
MVx=-0.075646922487205E-02;%AU/day
MVy=-2.370584048238274E-02;%AU/day
MVz=5.974096024543801E-08; %AU/day
MercuryInitial=[Mx,My,Mz,MVx,MVy,MVz];
%% Call the Function
%outpu=call the function, time to run, initial conditions
[attime,finalposition]=ode45(@Propagator,[0:stepsize:finaltime],[EarthInitial,MercuryInitial]); %% this is where the problem is when I added Mercuryinitial
%% Plot the Result
hold ON
plot3(finalposition(:,4),finalposition(:,5),finalposition(:,6),'g'); %plot of position of earth in green
plot3(finalposition(:,10),finalposition(:,11),finalposition(:,12),'g');
xlabel('Distance (AU)');ylabel('Distance (AU)');zlabel('Distance (AU)'); %label the axis
legend('Earth'); %tell me what the green line is
axis equal %fix the axis so it has the same scale in x, y and z
%note: sun is at 0,0,0
2 Kommentare
Steven Lord
am 18 Mai 2020
That doesn't look like the whole error message. Please show us all the text displayed in red and/or orange when you try to run your code.
Akzeptierte Antwort
Steven Lord
am 18 Mai 2020
Your initial condition vector has twelve elements, so the input to your ODE function Propagator will be a 12-by-1 vector. [As an aside, I would use a different name for the input argument than "input". For one thing it says effectively nothing about what that vector represents. Something like planetPositions would be more descriptive. For another, input already has a meaning in MATLAB. While you wouldn't want to call input in your ODE function because it would prompt the user at each timestep, it's a general good habit to get into not to use MATLAB function names for your variables.]
Your A1 variable is a 6-by-6 matrix. You can't multiply a 6-by-6 matrix and a 12-by-1 vector.
Perhaps you want to reshape the input to be a 6-by-2 matrix, perform the multiplication to receive a 6-by-2 matrix, and reshape the result back to 12-by-1 so it's the correct size for your ODE function to return?
2 Kommentare
Weitere Antworten (1)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!