Index exceeds the number of array elements. Index must not exceed 1.
2 views (last 30 days)
Show older comments
% 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.
Answers (1)
Walter Roberson
on 1 May 2023
Moved: Walter Roberson
on 1 May 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 Comments
See Also
Categories
Find more on Matrix Indexing 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!