Uploaded by Hana Bachi

docsity-matlab-code-engineering-analysis-using-numerical-methods-me-2004 (1)

advertisement
MATLAB Code | Engineering
Analysis Using Numerical
Methods | ME 2004
Mechanical Engineering
Virginia Polytechnic Institute and State University (Virginia Tech)
4 pag.
Document shared on www.docsity.com
Downloaded by: hanabachi (hanabachi11@gmail.com)
Problem 3.10, Chapra
Description
A simply supported beam is loaded as shown.
The deflection along the beam is
u y ( x) 

 5
x 0
6
4
 x 5
4
  156 x  8
3
 75 x  7
2

57 3
x  238.25 x
6
The singularity function is defined as
x a
n

 x  a  n


 0
,x  a
, x a
Objectives
1. Develop a function M-file to compute the singularity function.
2. Develop a function M-file to compute the displacement of the beam as a function of
position along the beam. The first line should be:
function uy = beamSimplySupported(x)
Use the singularity function developed in part (1).
3. Develop a separate “driver” function M-file to compute and plot the displacement of the
beam as a function of position.
Document shared on www.docsity.com
Downloaded by: hanabachi (hanabachi11@gmail.com)
MATLAB Code: Vectorized
function y = singularity(x,a,n)
% Syntax:
%
y = singularity(x,a,n)
% input:
%
x, a, n
% output:
%
y
y = (x-a).^n .* (x>a);
function uy = beamSimplySupported(x)
% Displacement along a simply supported beam
% syntax:
%
uy = beamSimplySupported(x)
% input:
%
x = position along beam (ft)
% output:
%
uy = displacement (ft)
uy = -5/6*( singularity(x,0,4) - singularity(x,5,4) )...
+ 15/6*singularity(x,8,3)...
+ 75*singularity(x,7,2) + 57/6*x.^3 - 238.25*x;
function beamSimplySupported_plot
%% Problem 3.10, Chapra
% Plot of the deflection of a simply supported beam.
% Vectorized
%% compute solution at each x
x = linspace(0,10);
uy = beamSimplySupported(x);
%% create plot
close all
plot(x,uy,'linewidth',2)
title('Deflection of a Simply Supported Beam')
xlabel('Position, x')
ylabel('Deflection, uy')
Document shared on www.docsity.com
Downloaded by: hanabachi (hanabachi11@gmail.com)
MATLAB Code: Non Vectorized
function y = singularity_NonVec(x,a,n)
% Syntax:
%
y = singularity(x,a,n)
% input:
%
x, a, n
% output:
%
y
if x <= a
y = 0;
else
y = (x-a).^n;
end
function uy = beamSimplySupported_NonVec(x)
% Displacement along a simply supported beam
% syntax:
%
uy = beamSimplySupported(x)
% input:
%
x = position along beam (ft)
% output:
%
uy = displacement (ft)
uy=-5/6*(singularity_NonVec(x,0,4)-singularity_NonVec(x,5,4))...
+ 15/6*singularity_NonVec(x,8,3)...
+ 75*singularity_NonVec(x,7,2) + 57/6*x.^3 - 238.25*x;
function beamSimplySupported_plot_NonVec
%% Problem 3.10, Chapra
% Plot of the deflection of a simply supported beam.
% Non-vectorized method
%% compute solution at each x
x = linspace(0,10);
uy = zeros(1,length(x));
for i = 1:length(x)
uy(i) = beamSimplySupported_NonVec(x(i));
end
%% create plot
close all
plot(x,uy)
title('Deflection of a Simply Supported Beam')
xlabel('Position, x (ft)'), ylabel('Deflection, uy (??)')
Document shared on www.docsity.com
Downloaded by: hanabachi (hanabachi11@gmail.com)
Results
Deflection of a Simply Supported Beam
0
-100
Deflection, uy
-200
-300
-400
-500
-600
0
1
2
3
4
5
6
Position, x
7
8
9
10
Comments
Both the vectorized and non-vectorized codes produce exactly the same graph. The vectorized
methodology is much more efficient and simple and is more natural with the basic data structure
in MATLAB: the MATtrix.
The units for the displacement are probably 10-6 ft since 500 ft displacements make no sense on a
real beam. We would have to study the original derivation of the beam displacement equation to
find out for sure.
Document shared on www.docsity.com
Downloaded by: hanabachi (hanabachi11@gmail.com)
Download