Skip to main content

6.8b Nonlinear least-squares labs

Source: Lab ideas from Computational Physics (Landau, Páez, Bordeianu), §6.8. Rewritten as original drills. Continues 6.8 Nonlinear fit to a resonance.

Build the pieces of a Breit-Wigner nonlinear fit one at a time: residuals, a finite-difference Jacobian entry, and a Newton-Raphson correction step. Stubs fail until filled in.

Fixed data

Table 6.1: E = [0,25,50,75,100,125,150,175,200], sigma = [10.6,16.0,45.0,83.5,52.8,19.9,10.8,8.25,4.7] (used as yiy_i here, σi≡1\sigma_i\equiv1).

Formula refresh​

Warm up: pick the matching equation among lookalikes (same walk as the theory lesson).

Labs​

Activity: Residual f1 at a guess

Implement g(x,a1,a2,a3)=a1/[(x−a2)2+a3]g(x,a_1,a_2,a_3)=a_1/[(x-a_2)^2+a_3] and the residual

f1(a1,a2,a3)=∑i=19yi−g(xi,a)(xi−a2)2+a3f_1(a_1,a_2,a_3)=\sum_{i=1}^{9}\frac{y_i-g(x_i,a)}{(x_i-a_2)^2+a_3}

over the fixed Table 6.1 data.

Input: a1 a2 a3. Print f1f_1 with 6 decimals.

Write-ups​

0/4 solved
6.8b.W1

Using “nonlinear”, “parameters”, and “closed form”, explain:

Why doesn't the Breit-Wigner fit have a closed-form solution like the linear regression in 6.6?

Minimum 3 words. Your answer must include: “nonlinear”, “parameters”, “closed form”.

0 words/ 3 min

Meet the writing requirements, then you can open the model answer.

Explorers​

# nonlinear_ref.py — Breit-Wigner residuals and forward-diff Jacobian (original sketch)
XS = [0, 25, 50, 75, 100, 125, 150, 175, 200]
YS = [10.6, 16.0, 45.0, 83.5, 52.8, 19.9, 10.8, 8.25, 4.7]

def g(x, a1, a2, a3):
return a1 / ((x - a2) ** 2 + a3)

def f1(a1, a2, a3):
return sum((YS[i] - g(XS[i], a1, a2, a3)) / ((XS[i] - a2) ** 2 + a3) for i in range(9))

Next: 7.3 Matrices in Python.