Attempted to access x(4); index out of bounds because numel(x)=2

1 view (last 30 days)
I understand my x vector is made of 2 numerals but how can I expand my matrix without changing the initial conditions vector?
% Set Variables
global m l cd g theta0 ft
m = 2.5; %[kg]
l = 12; %[m]
cd = 0.11; %[N-s/m]
g = 9.81; %[m/s^2]
theta0 = 45; % [rad]
[t,x] = ode45(@rocketEOM, [0 45], [0 0]); %computes 2 ODEs
ft = getThrust(t); %function calls thrust for a given time
here is my function file:
function xd = rocketEOM(t,x)
global m l cd g theta0 ft
% x(2) = x velocity
% x(4) = y velocity
xd = (ft/m) - (cd*hypot(x(2),x(4))/m) - g*sin(theta0);
end
  1 Comment
David Sanchez
David Sanchez on 14 Oct 2014
I think you are not defining your problem properly. In your function rocketEOM, you make use of x(2) and x(4). Why do not you call them x(1) and x(2) and solve the issue with the error?
Besides, rocketEOM uses ft before it is defined by getThrust.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!