help with a vibratonal analysis code
이전 댓글 표시
hi am still getting a hang of MATLAB havent been using it for so long and i keep getting an error message about 'The size of the indicated variable or array appears to be changing with each loop iteration.' been trying to fix this with no luck. i am doing a free vibration analysis of a 2 dof cantilever beam may i get help with my code. below is my whole script
m1=53;% Mass
m2=62.096;
k=3.096e+006 ; % Stiffness
c=150; % Damping
% 4 x 4 matrices
disp('4 x 4 Mass matrix');
mt=[c,0,m1,0;0,0,0,m2;m1,0,0,0;0,m2,0,0];
disp('4 x 4 stiffness matrix');
kt=[-m1,0,0,0;0,m2,0,0;0,0,3*k,-2*k;0,0,-2*k,2*k];
Z=mt\kt;
[V,D]=eig(Z);
disp('Eigenvalues');
V;
disp('Initial conditions');
x0=[0;0;0.005;0];
disp('Integration constants');
S=V\x0;
tk=linspace(0,2,101);
% Evaluation of time dependent response
% Recall that x1=y3 and x2=y4
for k=1:101
t=tk(k);
for i=3:4
x(k,i-2)=0;
for j=1:4
x(k,i-2)=0;
x(k,i-2)=x(k,i-2)+(real(S(j))*real(V(i,j))-imag(S(j))*imag(V(i,j)))*cos(imag(D(j,j))*t);
x(k,i-2)=x(k,i-2)+(imag(S(j))*real(V(i,j))-real(S(j))*imag(V(i,j)))*sin(imag(V(i,j))*t);
x(k,i-2)=x(k,i-2)*exp(-real(D(j,j))*t);
end
end
end
plot(tk,x(:,1),'-',tk,x(:,2),':')
title('free vibration of a viscously damped 2 DOF')
xlabel('t[sec]')
ylabel('x(m)')
legend('x1(t)','x2(t)')
채택된 답변
추가 답변 (1개)
Bruno Luong
2020년 8월 18일
"i keep getting an error message about 'The size of the indicated variable or array appears to be changing with each loop iteration."
However your code runs just fine.
If you want to remove it you need to preallocate the array x
x=zeros(101,2); % preallocation
for k=1:101
t=tk(k);
for i=3:4
x(k,i-2)=0;
...
카테고리
도움말 센터 및 File Exchange에서 Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!