% Function to calculate the deflection (y) and stress (s) of a cantilever beam

function [y,s] = cantiliverBeam(W,E,I,x,beamLength,distNeutralAxis)

% Date:
% Programmer: T. Trani
    
% Inputs to function cantiliverBeam

% W = load (lb)
% E = Modulus of elasticity (lb/sq-in)
% I = Moment of inertia (in-in-in-in)
% x = distance from datum point (in)
% l = beam length (in)
% distNeutralAxis = distance from edge of beam to neutral axis (in)

% Outputs of function cantiliverBeam

% y = deflection (in)
% s = stress at the cross-section being evaluated (lb/in-in)
% Z = section modulus of the cross section of the beam
% Z is calculated as I / distance from neutral axis to edge of the beam

% Calculations

y = -W * x.^2 ./ (24 * E * I * beamLength) .*(2 * beamLength^2 + (2 * beamLength - x).^2);
Z = I / distNeutralAxis;
s = W / (2 * Z * beamLength) .* (beamLength - x) .^2;


