Index exceeds the number of array elements. Index must not exceed 1.

2 次查看(过去 30 天)
% find the damping coefficient using the plot below (use the figure to do trial and error):
c_num = 500 ;
% define the time interval and the number of integration steps
n = 10000;
t = zeros(n,1);
tf = 5;
t(1) = 0;
delt = (tf-t(1))/n;
% initializing variables
x = zeros(n,1);
v = zeros(n,1);
m = 12 ; % kg
k = 10000 ; % N/m
J = 0.016 ; % kg m^2
r = 0.340 ; % m
% assign initial conditions (be careful of the units)
x(1) = 0.03 ; % m
v(1) = -0.2 ; % m/s
% start the integration directly from the second step (with i=2)
for i=2:1:n
% update the velocity and acceleration for x at step i
dx_ = v(i-1) ;
ddx_ = -(c_num*dx_(i-1) + k*x(i-1))/(m + J/r^2);
% integrate x and v
x(i) = x(i-1) + dx_*delt ;
v(i) = v(i-1) + (-c_num/m*v(i-1) - k/m*x(i-1))*delt ;
% integrate time
t(i) = t(i-1) + delt ;
end % end of each integration step
Index exceeds the number of array elements. Index must not exceed 1.
Please advise on the index error.

回答(1 个)

Walter Roberson
Walter Roberson 2023-5-1
移动:Walter Roberson 2023-5-1
dx_ = v(i-1) ;
dx_ will be a scalar
ddx_ = -(c_num*dx_(i-1) + k*x(i-1))/(m + J/r^2);
But you index it there.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by