← AI-pair numerics

Beam deflection

Cycle through mountings and loadings. For each combo, find the maximum deflection. Check it against algebra. Confidence builder before we get to eigenvalues.

1. Setup

Same Euler–Bernoulli beam as the next problem — length L, modulus E, area moment I, no inertia yet. Apply a static load, the beam deflects, the deflection w(x) satisfies

EI · d⁴w/dx⁴ = q(x)

with whatever boundary conditions your mounting imposes. You want: the maximum deflection δmax — how far does the beam move at its worst point?

Six cases live in any beam-deflection table:

cantilever      + tip point load P    ⇒  δ = PL³ / 3EI       at the tip
cantilever      + uniform load w      ⇒  δ = wL⁴ / 8EI       at the tip
simply supported + center point P    ⇒  δ = PL³ / 48EI      at midspan
simply supported + uniform load w    ⇒  δ = 5wL⁴ / 384EI    at midspan
clamped-clamped + center point P     ⇒  δ = PL³ / 192EI     at midspan
clamped-clamped + uniform load w     ⇒  δ = wL⁴ / 384EI     at midspan

All algebra. No calculus past integration to get those formulas in the first place. Roark's catalogs hundreds of variants.

2. Why this is an afternoon, not a week

Finite-element discretization with Hermite cubics turns EI w'''' = q into a linear system K u = f. Same element stiffness matrix as the vibration problem next door, no mass matrix needed for statics. The unknowns are nodal deflections and slopes; you assemble, apply BCs, solve once. Your brain picks the mesh, applies the mounting, builds the load vector, reads the answer.

3. Build it

Start with the cantilever-with-tip-load case. Hermite cubic elements, 10–20 of them across the beam. Assemble K, build f with the point load at the tip DOF, drop the fixed-end rows and columns, solve K u = f. Pull out δmax. Then point your AI pair at the next five cases — the differences are which DOFs you fix and how you build f.

Spec the discretization, the BC application strategy (row/column drop vs. penalty vs. Lagrange multipliers), and the consistent load vector for UDL with your AI pair. Have it draft. Your job is to specify, audit, verify.

4. Verification

Live below: pick a mounting, pick a loading, watch the beam deform to match. The closed-form formula sits next to the FEM number.

Mount:
Load:
Case: Cantilever, tip point load Algebra: δ = PL³ / 3EI = 0.33333 FEM (Hermite):   () Max at:
N = 20
Loading WASM…

Did you spot it? FEM error is zero to machine precision — even at N=2 elements. That's not the solver getting lucky; it's a deep property of Hermite cubic elements known as superconvergence. The deflection field of every classical case in the table above is a polynomial of degree ≤ 4, and the FEM galerkin equations recover those polynomials' nodal values exactly. Your shape functions happen to be the right shape.

This is why we start here. Three rungs of the verification ladder all pass trivially for this problem:

Rung 1 — analytical anchor. FEM matches closed-form to machine precision for every classical case.
Pass: exact agreement, all six cases.
Fail diagnosis: assembly or BC application is wrong — the algebra here doesn't leave room for "almost".
Rung 2 — conservation. Sum of nodal forces (including reactions) is zero. Verify by computing reactions from the K matrix times the solution.
Pass: residual < 10⁻¹⁰.
Rung 3 — mesh refinement. Halve the element size; for these classical cases, the answer doesn't change. Confidence-building, but mostly silent.
Pass: trivial — you're already exact.
Where this rung actually earns its keep: see "going further" below.

5. Hints

Hint 1 — frame it

Two unknowns per node: w and θ = dw/dx. The weak form needs C¹ continuity, so the slope is continuous across element boundaries, not just the displacement. Same setup as the vibration problem, minus the mass matrix.

Hint 2 — pick the tool

Hermite cubic shape functions, 4 per element. Element stiffness matrix Ke is a closed-form 4×4 you can find in any structural-dynamics text (Bathe, Cook). For the linear solve once you have K u = f: K is symmetric positive definite after BC application, so Cholesky is the cleanest choice. numpy.linalg.solve(K, f) also works.

Hint 3 — the gotcha (consistent load vector)

For a uniform distributed load w on an element of length le, the equivalent nodal forces are not just w le / 2 at each end. The correct consistent load vector is [wl/2, wl²/12, wl/2, -wl²/12] (the moment terms come from integrating the shape functions against the distributed load). Skipping the moment terms gives a convincing-looking-but-wrong answer.

Hint 4 — skeleton
def element_k(le, EI): ...           # 4x4 Hermite stiffness
def assemble_K(n_el): ...            # scatter into global K
def build_f(bc, load, n_el): ...     # consistent load vector
def apply_bcs(K, f, bc): ...         # drop fixed rows/cols
def solve(K, f): return np.linalg.solve(K, f)
def max_deflection(u, n_el): ...     # sample Hermite cubics, find argmax

6. Where to draw the line

For these six cases you could literally hard-code the closed-form table and skip the FEM entirely. That's not the point. The point is to wire up a solver you can trust — one whose answer on a trivial case you've checked by hand. Then you can push it past the table into territory where no algebraic formula exists (taper, asymmetric load, two point loads at once, stepped cross-section). This is the pattern: build a solver, verify it on the classical cases, then push.

7. One worked solution

Reveal the reference solver

The reference solver is the same Rust crate driving the live panel above. The static deflection routine is ~80 lines: solver/src/lib.rs, function deflect_static. Look for the consistent-load assembly for UDL, the row/column elimination for BC application, and the Cholesky solve.

Your solver probably looks different in shape — that's expected. What to compare:

Post-mortem from the author: skipped the moment terms in the UDL load vector first time around and got an answer ~10% off. The closed-form check caught it in 10 seconds. Wouldn't have caught it on a problem without an algebraic anchor.

8. Going further

When you're ready for the dynamic version of all this: Beam vibration →