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

조회 수: 2 (최근 30일)
Ryan
Ryan 2023년 5월 1일
이동: Walter Roberson 2023년 5월 1일
% 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