Index exceeds the number of array elements. Index must not exceed 1.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% 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
Please advise on the index error.
1 commentaire
Réponses (1)
Walter Roberson
le 1 Mai 2023
Déplacé(e) : Walter Roberson
le 1 Mai 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.
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!