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

1 view (last 30 days)
%% 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 Comments
Dyuman Joshi
Dyuman Joshi on 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

Sign in to comment.

Accepted Answer

VBBV
VBBV on 31 Mar 2023
Edited: VBBV on 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):')
Natural Frequencies (Hz):
disp(frequencies)
0 0 0 0
  3 Comments
VBBV
VBBV on 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):')
Natural Frequencies (Hz):
disp(frequencies.')
0.0038 0.0609 0.3085 0.9749

Sign in to comment.

More Answers (2)

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

Categories

Find more on Acoustics, Noise and Vibration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!