Lesson 26 (Capstone 2): Euler–Bernoulli Structural Beam Solver & Laser Deflection Calibration
Courses Integrated: Statics & Strength of
Materials + Calculus I (Week 5 Laser Beam Lab) + SymPy
/ SciPy / Materials Selection
Companion Dataset:
Solids_Cantilever_Beam_Deflection_Data.csv
Workflow Architecture
- Experimental Rig Calibration
(
curve_fit): Load measured cantilever laser deflections (0.0..2.0 mspan, uniform load \(w_0 = 600\text{ N/m}\)) fromSolids_Cantilever_Beam_Deflection_Data.csv, fit effective flexural rigidity \((EI)_{\text{eff}}\) directly against the analytical cantilever profile \(w(x) = \frac{w_0}{24 EI}(x^4 - 4 L x^3 + 6 L^2 x^2)\), and inspect measurement residuals. - General Multi-Load Beam Engine (
NumPy+ Macaulay): Solve arbitrary simply-supported shafts carrying distributed loads + multiple point forces (V(x),M(x),sigma_max(x),w(x)via cumulativeintegrate/ spline). - Ashby Minimum-Weight Beam Design: Rank
AISI 1018 Steel,Al 6061-T6,Al 7075-T6, andTi-6Al-4Vrectangular sections to satisfy BOTH stress (\(\text{FOS} \ge 2.0\)) and stiffness (\(\delta_{\max} \le L / 360\)).
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from pathlib import Path
from scipy.optimize import curve_fit
# --- Step 1: Fit Experimental Laser Cantilever Rig Data (Calc I Week 5 CSV!) ---
beam_p = next(p for p in [Path("datasets/Solids_Cantilever_Beam_Deflection_Data.csv"), Path("../datasets/Solids_Cantilever_Beam_Deflection_Data.csv")] if p.exists())
bdf = pd.read_csv(beam_p)
x_exp = bdf["Position_x_m"].values
w_exp_mm = bdf["Measured_Deflection_mm"].values
L_cant = 2.0
# Model w_mm(x) = C_coeff * (x^4 - 4*L*x^3 + 6*L^2*x^2) where C_coeff = 1000 * w0 / (24*EI)
def cant_model(x, c_val):
return c_val * (x**4 - 4.0*L_cant*(x**3) + 6.0*(L_cant**2)*(x**2))
popt, pcov = curve_fit(cant_model, x_exp, w_exp_mm, p0=[0.65])
c_fit = popt[0]
w0_N_m = 600.0 # Known calibrated sandbag test load [N/m]
EI_measured = (1000.0 * w0_N_m) / (24.0 * c_fit)
rmse_mm = np.sqrt(np.mean((cant_model(x_exp, c_fit) - w_exp_mm)**2))
print(f"=== Laser Rig Calibration (N={len(x_exp)} sensors) ===")
print(f"Fitted Bending Rigidity (EI)_eff = {EI_measured:,.1f} N*m^2 | Curve-Fit RMSE = {rmse_mm:.4f} mm")
# --- Step 2: General Multi-Load Simply-Supported Shaft V(x), M(x), w(x) Solver ---
def solve_beam(L_m, EI_val, w_unif_Nm, point_loads):
x = np.linspace(0.0, L_m, 1001)
# Sum moments about left pin A to get right reaction R_B:
sum_M_A = w_unif_Nm * L_m * (L_m / 2.0) + sum(P * a for P, a in point_loads)
R_B = sum_M_A / L_m
R_A = w_unif_Nm * L_m + sum(P for P, _ in point_loads) - R_B
V = R_A - w_unif_Nm * x
M = R_A * x - 0.5 * w_unif_Nm * (x**2)
for P, a in point_loads:
V = V - np.where(x >= a, P, 0.0)
M = M - np.where(x >= a, P * (x - a), 0.0)
# Double-integrate M(x)/EI cleanly with cumulative trapezoidal rule + linear enforcement w(0)=w(L)=0!
slope_raw = np.zeros_like(x)
slope_raw[1:] = np.cumsum(0.5 * (M[:-1] + M[1:]) * np.diff(x)) / EI_val
w_raw = np.zeros_like(x)
w_raw[1:] = np.cumsum(0.5 * (slope_raw[:-1] + slope_raw[1:]) * np.diff(x))
C1 = -w_raw[-1] / L_m
w_deflect = -(w_raw + C1 * x) # Downward deflection positive magnitude or signed (downward negative)
return x, V, M, w_deflect
x_g, V_g, M_g, w_g = solve_beam(L_m=3.6, EI_val=EI_measured * 20.0, w_unif_Nm=1200.0, point_loads=[(4500.0, 1.1), (3200.0, 2.5)])
print(f"\nMulti-Load Shaft (L=3.6 m): M_max = {M_g.max()/1000:.2f} kN*m | Max Deflection = {np.min(w_g)*1000:.2f} mm (L/360 = {3600/360:.1f} mm)")
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(11.0, 4.2))
xf = np.linspace(0, L_cant, 120)
ax1.scatter(x_exp, w_exp_mm, color="#dc2626", zorder=5, label="Laser Lab Data")
ax1.plot(xf, cant_model(xf, c_fit), "-", color="#0284c7", lw=2.2, label=f"Fitted Theory ($EI={EI_measured:,.0f}$ N$\\cdot$m$^2$)")
ax1.set_title("Cantilever Laser Deflection Identification"); ax1.set_xlabel("x [m]"); ax1.set_ylabel("Deflection [mm]"); ax1.grid(True, alpha=0.3); ax1.legend()
ax2.plot(x_g, M_g/1000.0, "-", color="#059669", lw=2, label="Bending Moment $M$ [kN$\\cdot$m]")
ax2.set_xlabel("Shaft Position $x$ [m]"); ax2.set_ylabel("Moment $M$ [kN$\\cdot$m]", color="#059669"); ax2.grid(True, alpha=0.3)
ax2r = ax2.twinx()
ax2r.plot(x_g, w_g*1000.0, "--", color="#dc2626", lw=2, label="Deflection $w$ [mm]")
ax2r.set_ylabel("Vertical Deflection [mm]", color="#dc2626")
ax2.set_title("Multi-Load Shaft Bending Moment & Elastic Curve")
fig.tight_layout()
=== Laser Rig Calibration (N=17 sensors) ===
Fitted Bending Rigidity (EI)_eff = 38,453.5 N*m^2 | Curve-Fit RMSE = 0.0258 mm
Multi-Load Shaft (L=3.6 m): M_max = 6.24 kN*m | Max Deflection = -0.00 mm (L/360 = 10.0 mm)
# --- Step 3: Ashby Minimum-Weight Rectangular Alloy Selector (Stress + L/360 Stiffness) ---
alloys = {
"AISI 1018 Steel": (7870, 205e9, 370e6),
"Al 6061-T6": (2700, 69e9, 276e6),
"Al 7075-T6": (2810, 72e9, 503e6),
"Ti-6Al-4V": (4430, 114e9, 880e6),
}
L_req, w_load, P_mid, width_m = 3.0, 1000.0, 4000.0, 0.050
M_max = (w_load * L_req**2) / 8.0 + (P_mid * L_req) / 4.0
w_limit = L_req / 360.0
print(f"Minimum-Weight Beam Sizing for M_max = {M_max/1000:.2f} kN*m, delta <= {w_limit*1000:.2f} mm:")
print(f"{'Alloy':<17} | {'Min h [mm]':>10} | {'Mass [kg]':>10} | {'Governing Mode'}")
print("-" * 62)
for name, (rho, E_v, Sy_v) in alloys.items():
# Stress req: M*(h/2)/(b*h^3/12) <= Sy/2 -> h_stress = sqrt(12*M / (b*Sy))
h_stress = np.sqrt((12.0 * M_max) / (width_m * Sy_v))
# Deflection check with equivalent center load approx delta <= (5wL^4/384 + PL^3/48)/(EI)
num_d = (5.0 * w_load * L_req**4 / 384.0) + (P_mid * L_req**3 / 48.0)
h_stiff = ((12.0 * num_d) / (E_v * width_m * w_limit)) ** (1.0 / 3.0)
h_gov = max(h_stress, h_stiff)
mode = "Strength" if h_stress >= h_stiff else "Stiffness (L/360)"
mass = rho * width_m * h_gov * L_req
print(f"{name:<17} | {h_gov*1000:10.1f} | {mass:10.2f} | {mode}")Minimum-Weight Beam Sizing for M_max = 4.12 kN*m, delta <= 8.33 mm:
Alloy | Min h [mm] | Mass [kg] | Governing Mode
--------------------------------------------------------------
AISI 1018 Steel | 77.4 | 91.41 | Stiffness (L/360)
Al 6061-T6 | 111.3 | 45.08 | Stiffness (L/360)
Al 7075-T6 | 109.7 | 46.26 | Stiffness (L/360)
Ti-6Al-4V | 94.2 | 62.57 | Stiffness (L/360)
Capstone Reflection & Challenge Questions
- Notice
Al 7075-T6was stiffness-governed whileAISI 1018 Steelwas lighter or heavier—which alloy won total mass savings when \(L/360\) deflection strictly governs? - Explain why the beam integration step
w_rawhad to subtract(-w_raw[-1]/L) * x: how do simply-supported boundary conditions \(w(0)=w(L)=0\) fix the integration slope constant \(C_1\)? - (Challenge): Replace the single-layer beam width
with an I-beam cross section (
flange_w,web_t) and verify how much beam weight drops!
🎬 Concept & Engineering Animation
🎬 Laser Cantilever Deflection