Subscript indices must either be real positive integers or logicals always show up. what should i do?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
%% 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 Commenti
Dyuman Joshi
il 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
Risposta accettata
VBBV
il 31 Mar 2023
Modificato: VBBV
il 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 Commenti
VBBV
il 1 Apr 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.')
Più risposte (2)
Alan Stevens
il 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
il 31 Mar 2023
See the FAQ for a thorough discussion of what causes the error and how to fix it:
0 Commenti
Vedere anche
Categorie
Scopri di più su Acoustics, Noise and Vibration in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!