# Elementary fitting

Top: Frida handbook
Up: Tutorial
Previous: Simple manipulations
Next: Fitting with convolution

In this tutorial session, we learn how to fit parametrized curves to given data, and how to extract the fitted parameters.

#### Basic example

Let us fit the instrumental resolution `gly180` by a Gaussian:

command action
? > fl gly180 load data file
0 > mr! abs(x)<2 restrict frequency range (the modified '!' means: operate “in place”, overwrite the input file)
0 > p 7 plot spectrum 7
0 > cc p0*exp(-(t-p1)^2/2/p2^2) create the fit curve (will be file 1)
1 > a 7 add to plot, with default initial values p0=p1=..=1
1 > cf fit (by default, the curve refers to data file 0)
1 > 0,1 p 7 replot data and fit
0,1 > 1 cp inform about curve, print parameters
1 > oi p2 create file containing p2 vs z0
2 > g4 new lin-lin plot window
2 > p plot p2 vs z0

Instead of the explicit formula p0*exp(-(t-p1)^2/2/p2^2), one could use the shorthand p0*gnn(t-p1,p2), where gnn stands for “gauss, not normalized”. The expression gauss(t,p2) is equivalent to the normal form 1/sqrt(2*pi)/p2*exp(-t^2/2/p2^2).

#### Fixing and setting parameters

Assume file 1 is a curve.

command action
1 > cx 2 fix parameter p2 to the current value
1 > op2 1.234 set parameter p2 to 1.234
1 > op2 pi/z0 arbitrary expressions may be used
1 > cf now fit, with p2 kept fixed at the previously set value
1 > cu 2 unfix p2

Last updated for Frida2.3.0c. 