You are on page 1of 1

clear all; close all; clc;

% Define beam parameters


L = 1; % Length of the beam [m]
E = 200e9; % Young's modulus of the beam [Pa]
rho = 7850; % Density of the beam [kg/m^3]
A = 0.1; % Cross-sectional area of the beam [m^2]
I = 0.005; % Second moment of inertia of the beam [m^4]
n=7;
% Discretize the beam into 100 elements
dx = L/n; % Length of each element [m]
x = 0:dx:L; % Coordinates along the beam [m]

% Assemble the stiffness matrix


K = zeros(n+1,n+1);
for i = 2:n
K(i,i) = K(i,i) + 24*E*I/dx^3;
K(i,i-1) = K(i,i-1) -12*E*I/dx^3;
K(i-1,i) = K(i-1,i) - 12*E*I/dx^3;
end
K(1,1) = K(1,1) + 12*E*I/dx^3;
K(n+1,n+1) = K(n+1,n+1) + 12*E*I/dx^3;

% Assemble the mass matrix


M = zeros(n+1,n+1);
for i = 2:n
M(i,i) = M(i,i) + rho*A*dx*156*2/420;
M(i,i-1) = M(i,i-1) + rho*A*dx*54/420;
M(i-1,i) = M(i-1,i) + rho*A*dx*54/420;
end
M(1,1) = M(1,1) + rho*A*dx*156;
M(n+1,n+1) = M(n+1,n+1) + rho*A*dx*156/420;

% Calculate the eigenfrequencies and eigenvectors


[V,D] = eig(K,M);
[f,ind] = sort(sqrt(diag(D))/(2*pi)); % Convert eigenvalues to
frequency [Hz]
V=V(:,ind);

% Plot the first 6 modes


for i = 1:6
figure;
plot(x,V(:,ind(i)));
% title(sprintf('Mode %d: f = %.2f Hz',i,f(i-1)));
xlabel('x [m]');
ylabel('Displacement [m]');
end

You might also like