You are on page 1of 2

clear all;

% Define beam properties


E = 20000000; % Young's modulus of steel
I = 100; % Moment of inertia
L = 2; % Length of beam
rho = 7850; % Density of steel
A = 1; % 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

% Define global stiffness matrix, and mass matrix


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

% Assemble global stiffness matrix, mass matrix


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

% Define fixed boundary condition

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 = sort(sqrt(diag(D)));
Disp(3:2*nnode,3:2*nnode)=V(:,:);
wn;

% Plot the first 6 mode shapes


for ii=1:6
i = 1:nnode;
figure;
plot(i, Disp(2*i-1,ii+2));
title(['Mode Shape ' num2str(i) ': Natural Frequency = '
num2str(wn(ii)) ' Hz']);
xlabel('Length of Beam');
end

You might also like