Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Lecture 9 · Trustworthy Numerical Answers

Week 5 · September 22, 2026

San Diego State University

When should we trust a numerical answer?

Last time: build a root finder and explain its stopping rule.

Today: propose → test → accept or revise → verify.

We will connect each advanced method to the problem it helps solve.

Recall · what does “small” mean?

  • Residual magnitude: ∣f(xn)∣|f(x_n)| measures equation mismatch; a signed residual keeps the sign.

  • Update: sn=∣xn−xn−1∣s_n=|x_n-x_{n-1}| measures the last move.

  • Bracket: a valid [an,bn][a_n,b_n] containing x∗x_* bounds midpoint error:

mn=an+bn2,∣mn−x∗∣≤bn−an2.m_n=\frac{a_n+b_n}{2},\qquad |m_n-x_*|\leq\frac{b_n-a_n}{2}.

Pair prompt: which assumptions turn each observation into evidence?

Why go beyond the basic methods?

The basic methods show how approximation, iteration, and stopping work.

Advanced methods become useful when:

  • A fast local step is unreliable from your starting guess.

  • Each function evaluation is expensive.

  • You fit many observations with a few parameters.

  • An integrand has structure that uniform sampling resolves inefficiently.

Goal: recognize the problem, choose a method, and check its answer.

Ask what information the problem gives you

What you haveWhat it enables
A continuous function and opposite endpoint signsBracket-based root control
Slopes or a local linear approximationFast trial steps
Predictions and observationsA least-squares objective
A callable integrandChoosing new sample locations

Discuss: if you only have fixed sampled data, can you freely choose Gaussian nodes?

A local model of f(x)f(x) proposes a step

The tangent line near xnx_n is our local model of f(x)f(x):

ℓn(x)=f(xn)+f′(xn)(x−xn),ℓn(xtrial)=0.\ell_n(x)=f(x_n)+f'(x_n)(x-x_n),\qquad \ell_n(x_{\rm trial})=0.
Arctangent curve and tangent at x equals two. The tangent root is near minus 3.536, far from the true root at zero.

Predict: Newton proposes the line’s zero. Will this step reduce ∣f(x)∣|f(x)|?

Separate direction from distance

p=−f(x)f′(x),xtrial=x+αp.p=-\frac{f(x)}{f'(x)},\qquad x_{\rm trial}=x+\alpha p.
  • Direction: Newton supplies pp.

  • Step length: a line search chooses α\alpha.

Trial rule: try the full step; shorten it if the acceptance test fails.

Define progress before accepting a step

Use a residual objective: ϕ(x)=12f(x)2\phi(x)=\tfrac12 f(x)^2.

For an exact Newton direction at a nonroot,

ϕ′(x)p=−f(x)2<0.\phi'(x)p=-f(x)^2<0.

A short enough step decreases this objective under the differentiability assumptions. A full step may not.

A half-step can be more useful

Residual merit along the Newton direction, with full step rejected and half-step accepted by the sufficient-decrease threshold.

Explain: acceptance is progress. What would establish convergence?

Demonstration · compare the trial steps

For f(x)=arctan⁡xf(x)=\arctan x at x=2x=2, the initial residual magnitude is 1.107.

Step fraction α\alphaTrial inputResidual magnitudeSufficient decrease?
1-3.5361.295No
1/21/2-0.7680.655Yes
1/41/40.6160.552Yes

Backtracking accepts the first passing trial. It need not find the best step.

Explain: why is acceptance not convergence?

When is a line search useful?

  • Use when: a local direction is promising but the full step overshoots.

  • Example: nonlinear calibration from an uncertain starting guess.

  • Check: actual objective decrease, not just the tangent’s prediction.

  • Cost: rejected trials require extra evaluations.

  • Limit: shorter steps cannot create a root. Check the domain, residual, and stopping conditions.

A bracket gives a different kind of protection

Arctangent with a verified bracket from minus one to two. The Newton proposal from two lies outside the bracket; the midpoint one half is an available fallback.

Predict: which endpoint should be replaced after evaluating f(0.5)>0f(0.5)>0?

Keep opposite signs. A fallback bisection step reduces the bracket width.

Safeguarded methods · fast proposals, controlled progress

Use a hybrid method when you have a valid bracket and want faster progress than bisection alone.

  1. Propose a fast step using local information.

  2. Check that it is safe and makes adequate progress.

  3. Otherwise, take a bracket-reducing step.

Brent-type methods combine interpolation and bisection; the preceding tangent example illustrates the safeguard idea, not Brent’s exact algorithm.

Continuity and reliable signs still matter.

From roots to fitting data

A residual is prediction minus observation: ri(θ)=g(ti;θ)−yir_i(\theta)=g(t_i;\theta)-y_i.

Choose parameters θ\theta to reduce Φ(θ)=12∑iri(θ)2\Phi(\theta)=\tfrac12\sum_i r_i(\theta)^2.

Illustrative observations and a candidate exponential curve. Vertical segments show prediction minus observation; changing curve parameters changes all residuals.

Noisy observations generally cannot all have zero residual.

The Jacobian · one slope for each input–output pair

Let r(θ)r(\theta) have mm outputs and θ\theta have nn parameters.

J(θ)=[∂r1∂θ1⋯∂r1∂θn⋮⋱⋮∂rm∂θ1⋯∂rm∂θn]∈Rm×n.J(\theta)=\begin{bmatrix} \dfrac{\partial r_1}{\partial\theta_1}&\cdots&\dfrac{\partial r_1}{\partial\theta_n}\\ \vdots&\ddots&\vdots\\ \dfrac{\partial r_m}{\partial\theta_1}&\cdots&\dfrac{\partial r_m}{\partial\theta_n} \end{bmatrix}\in\mathbb R^{m\times n}.
  • Row: one output’s sensitivity to all parameters.

  • Column: all outputs’ sensitivity to one parameter.

A partial derivative changes one parameter while holding the others fixed.

The matrix is a local input–output map

For a small parameter update pp,

r(θ+p)≈r(θ)+J(θ)p.r(\theta+p)\approx r(\theta)+J(\theta)p.

The dimensions tell us what this means:

J⏟m×n  p⏟n×1=Δrpredicted⏟m×1.\underbrace{J}_{m\times n}\;\underbrace{p}_{n\times1}=\underbrace{\Delta r_{\rm predicted}}_{m\times1}.

Component by component: Δri≈∑jJijpj\Delta r_i\approx\sum_j J_{ij}p_j.

Each entry has units “output ii per unit of parameter jj.”

Predict: is the Jacobian necessarily square?

Example · three observations, two parameters

Fit g(t;A,k)=Ae−ktg(t;A,k)=Ae^{-kt} to fixed observations yiy_i at t=0,1,2t=0,1,2.

For ri=Ae−kti−yir_i=Ae^{-kt_i}-y_i,

∂ri∂A=e−kti,∂ri∂k=−Atie−kti.\frac{\partial r_i}{\partial A}=e^{-kt_i},\qquad \frac{\partial r_i}{\partial k}=-At_i e^{-kt_i}.

Evaluate the slopes at the current parameters

At A=2A=2, k=ln⁡2k=\ln2, and t=0,1,2t=0,1,2:

J=[101/2−11/4−1]J=\begin{bmatrix}1&0\\1/2&-1\\1/4&-1\end{bmatrix}

Inputs are scaled and dimensionless.

Rows: observation times t=0,1,2t=0,1,2.

Columns: parameters AA and kk.

Explain: why is the top-right entry zero?

Use the Jacobian to predict a change

Increase AA by 0.10 and kk by 0.02:

p=[0.100.02],Jp=[101/2−11/4−1][0.100.02]=[0.100.030.005].p=\begin{bmatrix}0.10\\0.02\end{bmatrix},\qquad Jp=\begin{bmatrix}1&0\\1/2&-1\\1/4&-1\end{bmatrix} \begin{bmatrix}0.10\\0.02\end{bmatrix} =\begin{bmatrix}0.10\\0.03\\0.005\end{bmatrix}.

These are predicted changes in residuals, not the residuals themselves.

Increasing amplitude raises the curve; increasing decay rate lowers later values. The effects partly cancel.

Check: compare r(θ+p)−r(θ)r(\theta+p)-r(\theta) with JpJp, then reduce the step.

Check the local prediction against the actual change

For p=(0.10,0.02)p=(0.10,0.02), evaluate the exponential again:

TimePredicted JpJpActual change
00.1000000.100000
10.0300000.029209
20.0050000.004414

For 0.1p0.1p, the largest discrepancy falls from 7.91×10−47.91\times10^{-4} to 7.99×10−67.99\times10^{-6}: about 99×99\times smaller.

Explain: why does shrinking the step improve this linear prediction?

Read the least-squares notation

Transpose exchanges rows and columns:

rT=[r1,…,rm].r^{\mathsf T}=[r_1,\ldots,r_m].

Squared norm adds squared entries:

∥r∥2=rTr=∑iri2.\lVert r\rVert^2=r^{\mathsf T}r=\sum_i r_i^2.

Gradient: ∇θΦ\nabla_\theta\Phi has one loss derivative per parameter.

Nonsingular: a square matrix for which every right-hand side has exactly one solution.

JJ describes separate outputs; ∇Φ\nabla\Phi describes one scalar loss.

DS/ML · from many outputs to one loss

For least-squares loss Φ(θ)=12r(θ)Tr(θ)\Phi(\theta)=\tfrac12 r(\theta)^{\mathsf T}r(\theta),

∇θΦ=JTr.\nabla_\theta\Phi=J^{\mathsf T}r.

The Jacobian describes how parameters affect predictions; the loss gradient combines those effects into one direction of change.

Where it appears: nonlinear regression, calibration, and sensitivity of model predictions.

Backpropagation applies the chain rule through a model. It can compute products such as JTrJ^{\mathsf T}r without storing the full Jacobian.

This connection does not mean neural networks are usually trained with Levenberg–Marquardt.

Computational science · coupled equations

A steady state or implicit time step can require solving F(u)=0F(u)=0 for many unknowns.

Linearize the coupled equations:

F(u+p)≈F(u)+JF(u)p.F(u+p)\approx F(u)+J_F(u)p.

For a square, nonsingular Jacobian, Newton’s proposal solves

JF(u)p=−F(u).J_F(u)p=-F(u).

Examples: chemical equilibrium and coupled transport equations. Inverse problems instead often fit observations by minimizing a loss.

The Jacobian shows which variables affect which equations. Weak or dependent sensitivities can make the solve difficult.

Gauss–Newton · fit the local residual model

For a root, Newton sets a local approximation to zero.

For a fit, Gauss–Newton minimizes its squared mismatch:

minimize⁡p  12∥r+Jp∥2.\underset{p}{\operatorname{minimize}}\;\tfrac12\lVert r+Jp\rVert^2.

At a minimizer, JTJp=−JTrJ^{\mathsf T}Jp=-J^{\mathsf T}r.

A local fit can propose a large step where the approximation is poor.

Next question: can we discourage such large steps?

Derive a penalty on the proposed step

1. Define the penalized local fit in scaled parameters:

qλ(p)=12∥r+Jp∥2+λ2∥p∥2.q_\lambda(p)=\tfrac12\lVert r+Jp\rVert^2+\tfrac\lambda2\lVert p\rVert^2.

2. Differentiate with respect to the update pp:

∇pqλ=JT(r+Jp)+λp.\nabla_pq_\lambda=J^{\mathsf T}(r+Jp)+\lambda p.

3. Solve where the gradient is zero:

(JTJ+λI)p=−JTr.(J^{\mathsf T}J+\lambda I)p=-J^{\mathsf T}r.

The penalty limits the current step; it does not require parameters near zero.

Levenberg–Marquardt · damp the local fit

Local model: r(θ+p)≈r(θ)+Jpr(\theta+p)\approx r(\theta)+Jp.

Levenberg step:

(JTJ+λI)p=−JTr,θtrial=θ+p.(J^{\mathsf T}J+\lambda I)p=-J^{\mathsf T}r,\qquad \theta_{\rm trial}=\theta+p.
  • Jacobian: Jij=∂ri/∂θjJ_{ij}=\partial r_i/\partial\theta_j.

  • Update: pp changes the parameters.

  • Damping: λ>0\lambda>0 controls the penalty.

  • Identity: II leaves a vector unchanged.

Marquardt variants add scaling.

Accept only after checking: evaluate the actual fit improvement.

Read the contour plot before comparing steps

Contours: equal local squared mismatch.

q(p)=12∥r+Jp∥2q(p)=\tfrac12\lVert r+Jp\rVert^2

Cross: the local-model minimum.

Arrows: alternative damping choices from the same starting point, not successive iterations.

Contours of equal local squared mismatch. A cross marks the local-model minimum; four arrows start at zero and show alternative damping choices.

Damping changes the proposed direction

Labeled contours of the exponential model’s local squared residual and its minimum, with alternative damped proposals from zero. Increasing damping shortens and rotates the step toward the negative gradient direction.

Small damping: near the Gauss–Newton step when JTJJ^{\mathsf T}J is nonsingular.

Large damping: p≈−JTr/λp\approx-J^{\mathsf T}r/\lambda, a small gradient-like step.

Predict: does a tiny update establish a good fit?

When is Levenberg–Marquardt useful?

  • Use when: fitting smooth nonlinear models by least squares.

  • Example: calibration, decay curves, or parameter fitting.

  • Check: actual loss reduction, residual patterns, and parameter sensitivity.

  • Limit: a small residual does not establish unique or well-determined parameters.

Trial rule: scale parameters sensibly; adjust damping after checking each trial.

Decision case · fitting a decay curve

You fit noisy observations with Ae−ktAe^{-kt} from a poor initial guess.

  • Poor local prediction: damp the trial; compare predicted and actual loss reduction.

  • Different parameter scales: choose meaningful scales before applying λI\lambda I.

  • Only very early observations: sensitivity to kk is weak because ∂g/∂k=−Ate−kt\partial g/\partial k=-At e^{-kt}.

Discuss: can damping replace later observations that constrain the decay rate?

A stable numerical step does not establish that the data identify both parameters.

Three different ways to control a step

  • Line search: shorten a direction until it produces sufficient decrease.

  • Bracket safeguard: retain a valid bracket and replace unsafe proposals.

  • Levenberg damping: change the linear system proposing the direction.

Invariant: only the bracketed method carries a root bracket.

Integration · check the error model too

Adaptive quadrature: refine where local estimates indicate difficulty.

Richardson: cancel a leading error term when its expansion applies.

Predict: can two estimates agree because both missed the same feature?

Smaller reported error is evidence to investigate, not an unconditional certificate.

Where should we spend the next evaluation?

Uniform partition compared with an illustrative partition refined near a known localized feature. The partitions are supplied for explanation, not the output of an adaptive solver.
  • Uniform refinement: sample everywhere.

  • Local refinement: concentrate samples where needed.

The partition uses a known feature location; it is not an adaptive solver trace.

Agreement can mean that both estimates missed it

A narrow positive pulse lies between coarse nodes. All five sampled values are exactly zero, although the integral is positive.

Predict: what would coarse and refined rules report if both only see zeros?

Use known feature locations, interval splitting, and independent checks. An error estimator only sees what was sampled.

Richardson · use the error pattern

1. Assume Q(h)=I+Chp+higher-order termsQ(h)=I+Ch^p+\text{higher-order terms}.

2. Refine to Q(h/2)=I+Chp/2p+⋯Q(h/2)=I+Ch^p/2^p+\cdots.

3. Cancel the leading error:

R(h)=2pQ(h/2)−Q(h)2p−1.R(h)=\frac{2^p Q(h/2)-Q(h)}{2^p-1}.

Symbols: hh is spacing; pp is leading error order; II is the integral.

Predict: why would the wrong pp spoil cancellation?

Richardson works when the assumed pattern applies

Measured trapezoid and Richardson-combined absolute errors for the integral of cosine from zero to one, compared with sine of one. The smooth example shows second- and fourth-order refinement behavior.

Useful when a smooth problem has a stable error expansion at these resolutions.

Sharp features, insufficient resolution, or rounding can break that pattern.

Gauss–Legendre · choose nodes and weights

∫−11f(x) dx≈Qn=∑i=1nwif(xi).\int_{-1}^{1}f(x)\,dx\approx Q_n=\sum_{i=1}^{n}w_i f(x_i).

Nodes: xix_i specify where to evaluate. Weights: wiw_i set each contribution.

Two horizontal intervals from minus one to one. The endpoint trapezoid samples minus one and one, while two-node Gauss–Legendre samples plus and minus one over square root of three. All four displayed weights equal one.

Predict: for f(x)=x2f(x)=x^2, which sample locations give a better integral?

Two evaluations · compare the answers

For f(x)=x2f(x)=x^2, the exact integral on [−1,1][-1,1] is 2/32/3.

Endpoint trapezoid: QT=f(−1)+f(1)=2Q_T=f(-1)+f(1)=2.

Two-node Gauss–Legendre:

QG=f(−1/3)+f(1/3)=13+13=23.Q_G=f(-1/\sqrt3)+f(1/\sqrt3)=\tfrac13+\tfrac13=\tfrac23.

With nn nodes, Gauss–Legendre is exact for polynomials through degree 2n−12n-1 in exact arithmetic.

Limit: two nodes handle cubics exactly, but not every function. What check would you use for a new integrand?

See what the two rules measure

Left: endpoint trapezoid for x squared shades a rectangle of area two. Right: the true area under x squared is shaded, and Gaussian nodes have value one third with weights one, producing two thirds.
  • Left shading: trapezoid approximation.

  • Right shading: true integral.

Gaussian weights combine sampled values; they are not automatically widths of little panels.

When is Gauss–Legendre useful?

  • Use when: a smooth function can be evaluated at chosen nodes.

  • Example: an expensive integrand on a finite interval.

  • Check: compare orders or split the interval.

  • Limit: no built-in error estimate; treat discontinuities and endpoint singularities explicitly.

Exactness: nn nodes integrate polynomials through degree 2n−12n-1 in exact arithmetic. This does not extend to every smooth function.

Fixed measured samples usually require a different approach.

Map the nodes to your interval

Library nodes xix_i and weights wiw_i are defined on [−1,1][-1,1].

1. Map nodes to [a,b][a,b]:

ti=a+b2+b−a2xi.t_i=\frac{a+b}{2}+\frac{b-a}{2}x_i.

2. Scale weights by half the interval length:

∫abf(t) dt≈b−a2∑iwif(ti).\int_a^b f(t)\,dt\approx\frac{b-a}{2}\sum_i w_i f(t_i).

Check: for f=1f=1, the answer must be b−ab-a. Both transformations matter.

Convergence · which quantity contracts?

Actual bisection midpoint errors, bracket bounds, and Newton root errors for x squared minus two. Only positive measured errors are shown; zero cannot appear on a logarithmic axis.

Predict: can a midpoint become worse while its bracket becomes better?

Estimate order from three errors

Suppose consecutive errors are 10−1,10−2,10−410^{-1},10^{-2},10^{-4}.

p≈log⁡(en+1/en)log⁡(en/en−1)=2.p\approx\frac{\log(e_{n+1}/e_n)}{\log(e_n/e_{n-1})}=2.

Three errors support this estimate. A zero error cannot enter the logarithm.

A short triple suggests local behavior; it does not prove asymptotic order.

A bracket measures something different

Widths 1,1/2,1/4,1/81,1/2,1/4,1/8 have ratio 1/21/2.

The slope of log width against iteration is −log⁡2-\log2.

Actual midpoint errors need not decrease at every update.

Pair task: return to the convergence plot. Identify three consecutive positive Newton errors suitable for an order estimate. Find a bisection update where midpoint error rises while its bracket bound halves.

Fast convergence is not the same as low cost

Compare work at the same meaningful accuracy.

Count:

  • Function evaluations, including rejected trials.

  • Derivative evaluations.

  • Linear-system solves.

A higher-order quadrature rule uses more nodes per call. Cost also depends on what each evaluation computes.

Discuss: when could fewer iterations take longer?

Choose a method and a check

For one case, propose a method and an independent check:

  1. A continuous scalar equation with a sign-changing bracket.

  2. A nonlinear curve fitted to noisy observations.

  3. An integral with a known narrow feature.

Project 3 will implement and apply bisection, Newton, and secant. Today’s advanced methods are an overview.

Project 2 · protected work time

Due Wednesday, September 23, 11:59 pm PT

Choose your first unresolved check:

  • Separate cutoff error from quadrature refinement.

  • Recover the uniform-disk limit.

  • Explain convergence near a branch point.

  • Compare adaptive accuracy with actual evaluation counts.

Show the predicted result, measured result, and the smallest case that disagrees.

the acceptance rule

Armijo sufficient decrease:

ϕ(x+αp)≤ϕ(x)−cαf(x)2.\phi(x+\alpha p)\le\phi(x)-c\alpha f(x)^2.

The example uses c=10−4c=10^{-4} and halves α\alpha after rejection.

These are step-control settings, not root-accuracy tolerances. The reading contains the derivation and failure contract.

what a line search cannot promise

The merit function can have a stationary point with f≠0f\ne0.

For f(x)=x2+1f(x)=x^2+1, no real root exists, although ϕ\phi has a minimum at zero.

Inspect the equation, domain, and sensitivity. Treat stagnation and exhausted budgets as failures, not successful convergence.

Method overview

Optional conceptual follow-up; textbook implementations do not replace your project code.

SciPy’s least-squares documentation describes method="lm" (Levenberg–Marquardt). It does not support parameter bounds.

Course readings: Backtracking, Hybrid Methods, Adaptive Methods and Richardson Extrapolation.

Gaussian nodes in Python

NumPy leggauss(n) returns nn nodes and weights on [−1,1][-1,1].

SciPy roots_legendre(n) provides the same ingredients, with a worked interval-mapping example.

These functions do not evaluate your integrand or return its integral. You evaluate the function and form the weighted sum.

Optional exploration; does not replace required project implementations.

PyTorch: Jacobians and Jacobian products explains the automatic-differentiation connection.