Numerical methods

Two things a worksheet reaches for that have no closed form: where a function crosses zero, and the area under it. Both take the name of a function, the way map and iterate do, and both do a fixed amount of work rather than testing a tolerance — so both give the same bits on every machine.

A root, by bisection. It needs a bracket and says so if it does not have one.

fn f defined
r=root⁡(f,1,2)=1.41421
exact=2=1.41421

Dimensions travel through: a root of a length equation is a length.

fn overhang defined
a=root⁡(overhang,0⁢m,10⁢m)=3⁢m

root needs a bracket. roots needs only a window: it samples a fixed 200 intervals across it and bisects every sign change it finds. That is the question a worksheet usually has — where does this cross zero between here and here — when the answer may be one place, two, or none.

q0=2⁢kNm
span=2⁢m
fn V defined
where=roots⁡(V,0⁢m,span)=roots⁡(V,0⁢m,2⁢m)=1.08167⁢m

A wider window holds both zeros of the same parabola, and they come back in increasing order.

both=roots⁡(V,−2·span,2·span)=roots⁡(V,−2·2⁢m,2·2⁢m)=[-3.08167 m, 1.08167 m]

The slope of a function at a point, exactly: no step size, because every value carries how fast it is changing and every operation carries the chain rule.

fn area defined
dA=derivative⁡(area,2⁢m)=12.5664⁢m

The second derivative is where a curve turns, and it divides the dimension twice: a distance by a time twice over is an acceleration.

fn fall defined
a=derivative⁡(fall,3⁢s,2)=9.81⁢m/s²

Which is what makes a peak findable: it is where the slope crosses zero, so the two numerical methods compose.

fn gain defined
fn slope defined
atpeak=roots⁡(slope,1,5000)=1000
peak=gain⁡(atpeak)=gain⁡(1000)=500

A definite integral, by Simpson's rule over a fixed number of panels. Exact up to a cubic, which covers the load shapes a beam calculation actually uses.

fn q defined
area=integral⁡(q,0,2)=4

The resultant of a triangular distributed load, which is where this earns its place: the dimension falls out of f(x)·dx with no rule about integration.

wmax=10⁢kNm
L=3⁢m
fn w defined
R=integral⁡(w,0⁢m,L)=integral⁡(w,0⁢m,3⁢m)=15⁢kN

Its line of action, from the first moment of the same load.

fn wx defined
xbar=integral⁡(wx,0⁢m,L)R=integral⁡(wx,0⁢m,3⁢m)15⁢kN=2⁢m

A system of equations linear in its unknowns, which is what statics is: the reactions of a body under load. f is a residual — what is left over when the unknowns are substituted — and the second argument names them by dimension.

weight=10⁢kg·9.81⁢ms2=98.1⁢N
fn balance defined
reactions=solve_linear⁡(balance,[0⁢N0⁢N0⁢N])=[-39.05 N, 98.1 N, 59.05 N]

The Euclidean norm, and the unit vector that comes of dividing by it.

s=[34]⁢MPa
mag=norm⁡(s)=norm⁡([3000000 Pa, 4000000 Pa])=5⁢MPa
direction=smag=[3000000 Pa, 4000000 Pa]5⁢MPa=[0.6, 0.8]