help with a vibratonal analysis code
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
merina amon
el 18 de Ag. de 2020
Comentada: merina amon
el 20 de Ag. de 2020
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)')
0 comentarios
Respuesta aceptada
Stephan
el 18 de Ag. de 2020
Editada: Stephan
el 18 de Ag. de 2020
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
% preallocate x
x = zeros(numel(tk),2);
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)')
Más respuestas (1)
Bruno Luong
el 18 de Ag. de 2020
"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;
...
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!