function Pcr = beamPcr(A,I,Leff,E,Sy)
% beamPcr  Critical load for buckling of a beam under axial compression
%          ME 352 Fall 2008, Problem Set #2, Problem 8
%
% Synpopsis:  Pcr = beamPcr(A,I,Leff,E,Sy)
%
% Input:  A = area of cross section
%         I = moment of inertia of the cross section
%         Leff = effective length of the beam
%         E = elastic modulus of the beam material
%         Sy = yield stress of the beam material
%
% Output: Pcr = critical load for buckling.  If load exceeds Pcr the
%               beam will buckle

Sr = Leff/sqrt(I/A);     %  slenderness ratio
if Sr > pi*sqrt(2*E/Sy)
  Pcr = pi^2 * A*E/Sr^2;
else
  Pcr = A*(Sy - (1/E)*(Sy*Sr/(2*pi))^2 );
end