You are on page 1of 2

clear all;

% Define beam properties


E = 200e9; % Young's modulus of steel
I = 1e-4; % Moment of inertia
L = 2; % Length of beam
rho = 7850; % Density of steel
A = 1e-4; % Area of beam

% Define number of elements and nodes


nelem = 7; % Number of elements
nnode = nelem + 1; % Number of nodes

% Define element properties


Le = L/nelem; % Element length
me = rho*A*Le; % Mass per unit length

% Define global stiffness matrix, and mass matrix


K = zeros(nnode*2); % Global stiffness matrix
M = zeros(nnode*2); % Global mass matrix

% Assemble global stiffness matrix, mass matrix


for e = 1:nelem
% Define element stiffness matrix
ke = (E*I/Le^3) * [12 6*Le; 6*Le 4*Le^2];
% Define element mass matrix
mee = me*[1/3 1/2; 1/2 Le/3];
% Define element nodal coordinates
Xe = [(e-1)*Le e*Le]
% Define element nodal dofs
dofe = [2*e-1 2*e]
% Assemble element stiffness matrix, mass matrix into global
matrices
K(dofe, dofe)
M(dofe, dofe) = M(dofe, dofe) + mee;
end

% Define fixed boundary conditions


bc = [1 2]; % Nodal dofs for fixed boundary condition
dof = setdiff(1:nnode*2, bc); % Free dofs

% Solve for natural frequency and mode shape


[V,D] = eig(K(dof,dof),M(dof,dof));
[wn,indx] = sort(sqrt(diag(D)));
V = V(:,indx);

V;
wn;
% Plot the first 6 mode shapes
for i = 1:6
figure;
hold on;
plot(i, V(:,i));
title(['Mode Shape ' num2str(i) ': Natural Frequency = '
num2str(wn(i)) ' Hz']);
xlabel('Length of Beam');
end

You might also like