Subscript indices must either be real positive integers or logicals always show up. what should i do?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
%% Beam Properties
L = 0.35; % Length of the beam (m)
w = 0.02; % Width of the beam (m)
t = 0.002; % thickness of the beam (m)
m = 0.024; % Mass of the point mass (kg)
E = 200e6; % Young's Modulus (Pa)
rho = 7850; % Density of the material
Acs = w*t; %cross sectional area
I = w*t^3/12; %second moment of inertia
A = 2;
%% Calculation of Natural Frequencies and Mode Shapes
n = 4; % Number of modes to be calculated
beta = zeros(n,1);
for i = 1:n
beta(i) = (i*pi/L)^2;
end
omega = sqrt((beta.^4.*E*I)/rho.*Acs);
frequencies = omega/(2*pi); % Natural Frequencies in Hz
x = linspace(0,L,100); % Discretized beam length
mode_shape = zeros(n,length(x)); % Mode Shapes
for i = 1:n
mode_shape(i,:) = A(sin(beta*x)-sinh(beta*x)-((sin(beta*L)+sinh(beta*L))/(cos(beta*L)+cosh(beta*L)))*(cos(beta*x)-cosh(beta*x))); % Mode Shapes
mode_shape(i,:) = mode_shape(i,:)/max(abs(mode_shape(i,:))); % Normalize Mode Shapes
end
%% Plotting Mode Shapes
figure(1)
hold on
for i = 1:n
plot(x,mode_shape(i,:),'LineWidth',2)
end
xlabel('x (m)')
ylabel('Normalized Deflection')
title('Mode Shapes')
legend('Mode 1','Mode 2','Mode 3','Mode 4')
%% Displaying Natural Frequencies
disp('Natural Frequencies (Hz):')
disp(frequencies)
2 commentaires
Dyuman Joshi
le 31 Mar 2023
Do you mean to use beta(i) in this loop?
for i = 1:n
mode_shape(i,:) = A(sin(beta*x)-sinh(beta*x)-((sin(beta*L)+sinh(beta*L))/(cos(beta*L)+cosh(beta*L)))*(cos(beta*x)-cosh(beta*x))); % Mode Shapes
mode_shape(i,:) = mode_shape(i,:)/max(abs(mode_shape(i,:))); % Normalize Mode Shapes
end
Réponse acceptée
VBBV
le 31 Mar 2023
Modifié(e) : VBBV
le 31 Mar 2023
%% Beam Properties
L = 0.35; % Length of the beam (m)
w = 0.02; % Width of the beam (m)
t = 0.002; % thickness of the beam (m)
m = 0.024; % Mass of the point mass (kg)
E = 200e6; % Young's Modulus (Pa)
rho = 7850; % Density of the material
Acs = w*t; %cross sectional area
I = w*t^3/12; %second moment of inertia
A = 2;
%% Calculation of Natural Frequencies and Mode Shapes
n = 4; % Number of modes to be calculated
beta = zeros(n,1);
omega = sqrt((beta.^4.*E*I)/rho.*Acs);
frequencies = omega/(2*pi); % Natural Frequencies in Hz
x = linspace(0,L,100); % Discretized beam length
mode_shape = zeros(n,100);
M = {'--','-.','-',':'}; % set linestyles
%% Plotting Mode Shapes
hold on
for i = 1:n
beta(i) = (i*pi/L)^2;
mode_shape(i,:) = A*(sin(beta(i)*x*pi/180)-sinh(beta(i)*x*pi/180)-((sin(beta(i)*L*pi/180)+sinh(beta(i)*L*pi/180))./(cos(beta(i)*L*pi/180)+cosh(beta(i)*L*pi/180))).*(cos(beta(i)*x*pi/180)-cosh(beta(i)*x*pi/180))); % Mode Shapes
mode_shape(i,:) = mode_shape(i,:)./max(abs(mode_shape(i,:))); % Normalize Mode Shapes
plot(x,mode_shape(i,:),'LineWidth',2,'LineStyle',M{i})
end
xlabel('x (m)')
ylabel('Normalized Deflection')
title('Mode Shapes')
legend('Mode 1','Mode 2','Mode 3','Mode 4'); grid
%% Displaying Natural Frequencies
disp('Natural Frequencies (Hz):')
disp(frequencies)
3 commentaires
VBBV
le 1 Avr 2023
%% Beam Properties
L = 0.35; % Length of the beam (m)
w = 0.02; % Width of the beam (m)
t = 0.002; % thickness of the beam (m)
m = 0.024; % Mass of the point mass (kg)
E = 200e6; % Young's Modulus (Pa)
rho = 7850; % Density of the material
Acs = w*t; %cross sectional area
I = w*t^3/12; %second moment of inertia
A = 2;
%% Calculation of Natural Frequencies and Mode Shapes
n = 4; % Number of modes to be calculated
beta = zeros(n,1);
% Natural Frequencies in Hz
x = linspace(0,L,100); % Discretized beam length
mode_shape = zeros(n,100);
M = {'--','-.','-',':'}; % set linestyles
%% Plotting Mode Shapes
hold on
for i = 1:n
beta(i) = (i*pi/L)^2;
omega(i) = sqrt((beta(i)^4.*E*I)/rho.*Acs); % omega
frequencies(i) = omega(i)/(2*pi); % frequencies
mode_shape(i,:) = A*(sin(beta(i)*x*pi/180)-sinh(beta(i)*x*pi/180)-((sin(beta(i)*L*pi/180)+sinh(beta(i)*L*pi/180))./(cos(beta(i)*L*pi/180)+cosh(beta(i)*L*pi/180))).*(cos(beta(i)*x*pi/180)-cosh(beta(i)*x*pi/180))); % Mode Shapes
mode_shape(i,:) = mode_shape(i,:)./max(abs(mode_shape(i,:))); % Normalize Mode Shapes
plot(x,mode_shape(i,:),'LineWidth',2,'LineStyle',M{i})
end
xlabel('x (m)')
ylabel('Normalized Deflection')
title('Mode Shapes')
legend('Mode 1','Mode 2','Mode 3','Mode 4'); grid
%% Displaying Natural Frequencies
disp('Natural Frequencies (Hz):')
disp(frequencies.')
Plus de réponses (2)
Alan Stevens
le 31 Mar 2023
Well, this works, but you might want to check the correctness or otherwise of your mode_shape calculations (there are a lot of zeros there!)
%% Beam Properties
L = 0.35; % Length of the beam (m)
w = 0.02; % Width of the beam (m)
t = 0.002; % thickness of the beam (m)
m = 0.024; % Mass of the point mass (kg)
E = 200e6; % Young's Modulus (Pa)
rho = 7850; % Density of the material
Acs = w*t; %cross sectional area
I = w*t^3/12; %second moment of inertia
A = 2;
%% Calculation of Natural Frequencies and Mode Shapes
n = 4; % Number of modes to be calculated
beta = zeros(n,1);
for i = 1:n
beta(i) = (i*pi/L)^2;
end
omega = sqrt((beta.^4.*E*I)/rho.*Acs);
frequencies = omega/(2*pi); % Natural Frequencies in Hz
x = linspace(0,L,100); % Discretized beam length
mode_shape = zeros(n,100);
for i = 1:n
mode_shape(i,:) = A*(sin(beta(i)*x)-sinh(beta(i)*x)-((sin(beta(i)*L)+sinh(beta(i)*L))./(cos(beta(i)*L)+cosh(beta(i)*L))).*(cos(beta(i)*x)-cosh(beta(i)*x))); % Mode Shapes
mode_shape(i,:) = mode_shape(i,:)./max(abs(mode_shape(i,:))); % Normalize Mode Shapes
end
%% Plotting Mode Shapes
figure(1)
hold on
for i = 1:n
plot(x,mode_shape(i,:),'LineWidth',2)
end
xlabel('x (m)')
ylabel('Normalized Deflection')
title('Mode Shapes')
legend('Mode 1','Mode 2','Mode 3','Mode 4')
%% Displaying Natural Frequencies
disp('Natural Frequencies (Hz):')
disp(frequencies)
Image Analyst
le 31 Mar 2023
See the FAQ for a thorough discussion of what causes the error and how to fix it:
0 commentaires
Voir également
Catégories
En savoir plus sur Acoustics, Noise and Vibration 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!