Filter löschen
Filter löschen

"Index exceeds matrix dimensions."

1 Ansicht (letzte 30 Tage)
Mauro De Francesco
Mauro De Francesco am 26 Sep. 2017
Beantwortet: KSSV am 26 Sep. 2017
Hello, I'm having a problem with this code
%%DATA
%Starting Point
R_I = [-5.5106881000000003e+03 1.5889450000000002e+03 5.8383016000000007e+03];
V_I = [-3.8639999999999999e+00 -6.5410000000000004e+00 -1.2840000000000000e+00];
%Planet
mi = 398600;
equat_Rt = 6378.1363;
polar_Rt = 6356.7523142;
%%COMPUTIING
t_0 = 0.1;
t_f = 100000;
options = odeset('Reltol',1e-13,'Abstol',1e-14,'Event',@closed_orbit);
X_0 = [R_I(1); R_I(2); R_I(3); V_I(1); V_I(2); V_I(3)];
[T,X] = ode113(@orbit_dynamics,[t_0 t_f],X_0,options,mi,R_I);
The function orbit_dynamics is this one
function [dX] = orbit_dynamics(X,mi,varargin)
x = X(1);
y = X(2);
z = X(3);
u = X(4);
v = X(5);
w = X(6);
% Position derivative is velocity
dx = u;
dy = v;
dz = w;
% Velocity derivative is acceleration
R = [x,y,z];
norm_R = norm(R);
du = -mi/norm_R^3 * x;
dv = -mi/norm_R^3 * y;
dw = -mi/norm_R^3 * z;
% Terminating data
dX = [dx dy dz du dv dw]';
end
The error that Matlab gives is
Index exceeds matrix dimensions.
Error in orbit_dynamics (line 4)
y = X(2);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode113 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in orbit_motion (line 18)
[T,X] = ode113(@orbit_dynamics,[t_0 t_f],X_0,options,mi,R_I);
I ran the debug and it seems that when it enters the function orbit_dynamics, the vector X turns in a 1x1 vector, can anyone help me with that?
  1 Kommentar
Mauro De Francesco
Mauro De Francesco am 26 Sep. 2017
Solved the problem. The function should have been
function [dX] = orbit_dynamics(t,X,mi,varargin)
notice the t. If there is no explicit time dependency (autonomous system) however, you can replace t with ~. Hope this helps someone.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KSSV
KSSV am 26 Sep. 2017
Change the function:
[dX] = orbit_dynamics(X,mi,varargin) ;
to
[dX] = orbit_dynamics(t,X,mi,varargin) ;

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by