Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
% 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.

Risposte (1)

Walter Roberson
Walter Roberson il 1 Mag 2023
Spostato: Walter Roberson il 1 Mag 2023
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.

Community Treasure Hunt

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

Start Hunting!

Translated by