%  Problem 3 - Exam II - Spring 2012

%  This routine computes the Gerber and modified Goodman safety factors of
%  a stepped steel rod undergoing both axial and torsional stresses

% Shear stress mean =     18.9 MPa
% Shear stress alt =      9.4 MPa
% Axial stress mean =      1.4 MPa
% Axial Stress Alt =      0.7 MPa
% 
% Axial Stress Kf =    2.415
% Axial Stress Kfm =    2.415
% Shear Stress Kfs =    2.002
% 
% von Mises Alternating Stress =     32.8 MPa
% von Mises Mean Stress =     65.5 MPa
% 
% N Goodman =      3.7
% N Gerber =      4.6

Sut = 600;                      %  Ultimate tensile stress (MPa)
Se = 200;                       %  Endurance strength (MPa)
Sy = 480;                       %  Yield stress (MPa)
Fillet = 0.1;                   %  Fillet radius in mm
Diameter = 30;                  %  the smaller shaft diameter
Kt = 4.1;                       %  static axial stress concentration factor
Kts = 2.9;                      %  static axial stress concentration factor

%  Compute the alternating and midrange shear due to the torque

TorqueMean = 100 * 1000;        %  Applied mean torque in Newton mm
Tm = Shear_Round_Torque_m(Diameter, TorqueMean);
Ta = 0.5 * Tm;

%  Compute the alternating and midrange stress due to the axial loading

Area = pi * Diameter ^ 2 / 4;
Sm = 1000 / Area;           %  Axial stress in MPa
Sa = 0.5 * Sm;

%  Reduce the stress concentration factors due to fatigue

Kfs = Stress_Reduce_Torque_m(Kts, Fillet, Sut);
Kf = Stress_Reduce_Bend_m(Kt, Fillet, Sut);

%  Check for local bending

Kfm = Local_Yielding(Kf, Sa, Sm, Kfs, Ta, Tm, Sy);

%  Compute the von Mises Stresses due to alternating and mean loads

VMalt  = VM_Stress_Alt (Kf, 0, Kf, Sa, Kfs, Ta);
VMmean = VM_Stress_Mean(Kfm, 0.0, Kfm, Sm, Kfs, Tm);

%  Compute the modified Goodman and Gerber safety factors

Ngoodman = Goodman(VMalt, VMmean, Se, Sut);
Ngerber = Gerber(VMalt, VMmean, Se, Sut);

%  Print the results

fprintf('\nShear stress mean = %8.1f MPa\n', Tm);
fprintf('Shear stress alt = %8.1f MPa\n', Ta);
fprintf('Axial stress mean = %8.1f MPa\n', Sm);
fprintf('Axial Stress Alt = %8.1f MPa\n\n', Sa);

fprintf('Axial Stress Kf = %8.3f\n', Kf);
fprintf('Axial Stress Kfm = %8.3f\n', Kfm);
fprintf('Shear Stress Kfs = %8.3f\n\n', Kfs);

fprintf('von Mises Alternating Stress = %8.1f MPa\n', VMalt);
fprintf('von Mises Mean Stress = %8.1f MPa\n\n', VMmean);

fprintf('N Goodman = %8.1f\n', Ngoodman);
fprintf('N Gerber = %8.1f\n', Ngerber);





