index out of bounds because of numel????
Show older comments
Hi,
I am having Problems with the below function and script.
function [ xdot ] = aq_1( t,x )
global m c k y
xdot(1) = x(2);
xdot(2) = (1/m)*((2*k*y)-c*x(2)-2*k*x(1));
xdot=[xdot(1);xdot(2)];
end
global m c k y
m=500*9.81;%Mass of object M = 500kg
c=400; %Dampening coefficient of shock absorber c = 400Ns/m
k=5; %Spring stiffness of each spring k = 5kN/m
tspan=[0:0.01:10];
b=0.05;%bump in metres
v=11.11;%velocity v = 40km/h or 11.11m/s
s=v*tspan;
w=2*pi/2;
y = b*sin(w*s);
[t,x]=ode45('aq_1',tspan,0);
plot(t,x(:,2))
This is the series of warnings I get below. I can't get my head around the first one of being out of bounds and can't find what a numel is.
I know it is a bit of an ask but I would appreciate the help.
Thanks
Attempted to access x(2); index out of bounds because
numel(x)=1.
Error in aq_1 (line 3)
xdot(1) = x(2);
Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1}
to yp0.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0,
odeArgs, odeFcn, ...
Accepted Answer
More Answers (0)
Categories
Find more on Programming 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!