Subscript indices must either be real positive integers or logicals always show up. what should i do?

1 次查看(过去 30 天)
%% 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 个评论
Dyuman Joshi
Dyuman Joshi 2023-3-31
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

请先登录,再进行评论。

采纳的回答

VBBV
VBBV 2023-3-31
编辑:VBBV 2023-3-31
%% 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):')
Natural Frequencies (Hz):
disp(frequencies)
0 0 0 0
  3 个评论
VBBV
VBBV 2023-4-1
%% 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):')
Natural Frequencies (Hz):
disp(frequencies.')
0.0038 0.0609 0.3085 0.9749

请先登录,再进行评论。

更多回答(2 个)

Alan Stevens
Alan Stevens 2023-3-31
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
Image Analyst 2023-3-31
See the FAQ for a thorough discussion of what causes the error and how to fix it:

类别

Help CenterFile Exchange 中查找有关 Acoustics, Noise and Vibration 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by