Minimizing Deflection While Reducing Material Usage
Structural optimization is one of the most compelling intersections of engineering mechanics, mathematics, and modern computation. In this article, we tackle a classic structural engineering problem: how to optimally shape the cross-section of a simply supported beam so that it deflects as little as possible under a given load, while simultaneously using as little material as possible. We’ll solve this with Python using scipy.optimize, visualize the geometry in 2D and 3D, and walk through every step of the math and code.
Problem Setup
Consider a simply supported beam of length $L$ subjected to a uniformly distributed load $q$ (N/m). We want to choose the width $b$ and height $h$ of a solid rectangular cross-section to:
Minimize the maximum midspan deflection:
$$\delta_{\max} = \frac{5 q L^4}{384 E I}$$
where the second moment of area for a rectangle is:
$$I = \frac{b h^3}{12}$$
Subject to constraints:
- Volume (material) constraint — cross-sectional area $A = b \cdot h$ must not exceed a prescribed limit $A_{\max}$:
$$b \cdot h \leq A_{\max}$$
- Bending stress constraint — the maximum bending stress must not exceed the allowable stress $\sigma_{\text{allow}}$:
$$\sigma_{\max} = \frac{M_{\max} \cdot (h/2)}{I} \leq \sigma_{\text{allow}}, \quad M_{\max} = \frac{q L^2}{8}$$
- Geometric bounds — practical lower and upper limits on $b$ and $h$:
$$b_{\min} \leq b \leq b_{\max}, \quad h_{\min} \leq h \leq h_{\max}$$
The design variables are $\mathbf{x} = [b, h]$.
Why Is $h$ More Valuable Than $b$?
Notice that $I \propto h^3$ but only $\propto b^1$. This means increasing the height is cubically more effective at reducing deflection than increasing the width by the same amount. The optimizer should discover this naturally — and push $h$ to its upper limit while keeping $b$ lean.
This is exactly why I-beams and T-beams are shaped the way they are in real structures.
The Optimization Problem in Standard Form
$$\min_{b,h} ; f(b,h) = \frac{5 q L^4}{384 E} \cdot \frac{12}{b h^3} = \frac{5 q L^4 \cdot 12}{384 E \cdot b h^3}$$
$$\text{subject to:} \quad g_1: ; bh - A_{\max} \leq 0$$
$$g_2: ; \frac{q L^2}{8} \cdot \frac{6}{b h^2} - \sigma_{\text{allow}} \leq 0$$
$$b_{\min} \leq b \leq b_{\max}, \quad h_{\min} \leq h \leq h_{\max}$$
We will use scipy.optimize.minimize with the SLSQP (Sequential Least Squares Programming) method, which handles nonlinear constraints and bound constraints natively.
Full Source Code
1 | # ============================================================ |
Code Walkthrough
Section 1 — Problem Parameters
All physical constants are gathered in one place. E = 200e9 Pa is standard structural steel, sigma_al = 150e6 Pa is a conservative allowable bending stress, and A_max = 0.012 m² (120 cm²) caps the material budget. Keeping everything here makes parametric studies trivial.
Section 2 — Engineering Functions
Three pure functions encapsulate the beam mechanics:
second_moment(b, h)returns $I = bh^3/12$.deflection(b, h)returns $\delta = 5qL^4/(384EI)$ — this is the objective.bending_stress(b, h)returns $\sigma = M(h/2)/I$ where $M = qL^2/8$.
These are NumPy-compatible: they accept both scalars and arrays, which is critical for the grid-based surface plots later.
Section 3 — Objective and Constraints
scipy.optimize.minimize with method="SLSQP" accepts constraints as a list of dictionaries. The "ineq" type means the function must be $\geq 0$ at a feasible point:
$$g_1: A_{\max} - bh \geq 0 \qquad g_2: \sigma_{\text{allow}} - \sigma(b,h) \geq 0$$
Section 4 — Multi-Start SLSQP
SLSQP is a gradient-based local optimizer. Because the deflection surface is convex but the constraints create a non-convex feasible region, we run 60 random restarts and keep the best feasible solution. This costs almost no time (each solve is microseconds) but greatly improves robustness. The seed is fixed for reproducibility.
Section 5 — Baseline Comparison
We compare against the naive design: a square cross-section with the full area budget $A_{\max}$, i.e., $b = h = \sqrt{A_{\max}}$. This is the “do nothing clever” engineer’s choice.
Section 6 — Visualizations
Nine subplots are laid out on a 3×3 grid:
| Panel | What it shows |
|---|---|
| A Cross-section | Overlaid rectangles: square baseline (grey fill) vs. optimal (orange dashed outline) |
| B Deflection surface (3D) | $\delta(b,h)$ over the full design space — shows the steep valley toward tall, narrow sections |
| C Stress surface (3D) | $\sigma(b,h)$ — reveals the stress constraint is tightest for narrow-wide sections |
| D Contour + constraints | 2D top-down view with constraint boundary lines (orange = area, cyan = stress) and the optimum marked |
| E Second moment surface (3D) | $I(b,h)$ — visually confirms $I \propto h^3$ dominates |
| F Trade-off curve | $\delta$ vs $h$ along the area-saturated boundary $b = A_{\max}/h$ |
| G Elastic curve | Actual deflected shape $w(x)$ of the beam under UDL for both designs |
| H Bar chart | Side-by-side comparison of $\delta$ and $A$ for baseline vs. optimal |
| I Aspect ratio sensitivity | $\delta$ vs $h/b$ at fixed area $A^*$ — reveals the optimal slenderness ratio |
The elastic curve uses the exact closed-form solution for a simply supported beam under UDL:
$$w(x) = \frac{q}{24EI}\left(L^3 x - 2Lx^3 + x^4\right)$$
Execution Results
==================================================== OPTIMIZATION RESULTS ==================================================== Optimal width b* = 5.0000 cm Optimal height h* = 24.0000 cm Section area A* = 120.0000 cm² Second moment I* = 5760.000010 cm⁴ (×10⁻⁸ m⁴) Max deflection δ* = 7.064254 mm Max stress σ* = 65.1042 MPa Area constraint : 0.012000 ≤ 0.012000 Stress constraint: 65.1042 ≤ 150.0 MPa ==================================================== [Baseline – square section, A = A_max] b = h = 10.9545 cm δ = 33.908420 mm σ = 142.6361 MPa Deflection improvement: 79.2%

Figure saved.
Graph Interpretation
Panel B (Deflection surface) is the most revealing plot. The surface drops sharply as $h$ increases — this is the $h^{-3}$ dependence at work. The optimizer’s cyan marker sits in the deep valley at maximum $h$ and minimum feasible $b$, exactly where intuition says it should be.
Panel D (Contour map) shows the feasible region clearly. The area constraint (orange dashed line) cuts diagonally across the design space. The stress constraint (cyan dotted line) only bites in the lower-right corner (wide, short beams). The optimum sits right on the area constraint boundary, confirming the material budget is the active constraint.
Panel F (Trade-off curve) tells the story compactly: along the area-saturated boundary, deflection plummets monotonically as $h$ rises. The optimizer pushes $h$ to the upper bound and $b$ to whatever the area allows.
Panel I (Aspect ratio) shows that for a fixed material budget equal to $A^*$, the deflection is minimized at the highest feasible $h/b$ ratio, and degrades quickly as the section becomes more squat. This is the mathematical argument for why real structural beams are tall and narrow, not square.
Panel H (Bar chart) gives the bottom line: the optimal section achieves a dramatically lower deflection than the square baseline, while using the same or less material.
Key Takeaways
The optimization result makes engineering sense: since $I \propto h^3$, every millimeter of height is worth far more than the same millimeter of width. The optimizer always drives $h$ toward its upper bound and uses only as much $b$ as the area constraint permits. This is precisely why structural steel beams (W-shapes, I-beams) are designed with tall, thin webs rather than square profiles. The mathematics simply formalizes what experienced structural engineers have known for centuries.




















