Session 4: Elementary Fitting
In this session we fit parametrized curves to data and extract the fitted parameters.
Basic example: fit a Gaussian to the resolution
We fit the instrumental resolution file gly180 with a Gaussian
function.
| Command | Action |
|---|---|
? > fl gly180 |
Load the data file |
0 > mr! abs(x)<2 |
Restrict the frequency range in-place (! means overwrite) |
0 > p 7 |
Plot spectrum 7 |
0 > cc p0*exp(-(t-p1)^2/2/p2^2) |
Create a fit curve (stored as file 1) |
1 > a 7 |
Add curve to plot with default initial values p0=p1=p2=1 |
1 > cf |
Fit (by default, the curve fits data file 0) |
1 > 0,1 p 7 |
Replot data and fit together |
0,1 > 1 cp |
Print the fitted parameters |
1 > oi p2 |
Create a file of p2 vs z0 |
2 > g4 |
Open a new linear-linear plot window |
2 > p |
Plot p2 vs z0 |
Tip: Instead of writing out the full Gaussian formula, you can use
the shorthand p0*gnn(t-p1, p2), where gnn stands for “Gauss, not
normalized”. The expression gauss(t, p2) gives the normalized form
exp(-t^2/2/p2^2) / sqrt(2*pi) / p2.
Fixing and setting parameters
Assume file 1 is a curve file.
| Command | Action |
|---|---|
1 > cx 2 |
Fix parameter p2 to its current value |
1 > op2 1.234 |
Set p2 to a specific value |
1 > op2 pi/z0 |
Set p2 using an arbitrary expression |
1 > cf |
Fit with p2 held fixed |
1 > cu 2 |
Unfix p2 |