<a href="#fitFunction">fitFunction</a> | 
<a href="#fitMultiFunction">fitMultiFunction</a><br>


<p>

<!--------------------------------------------------------->
<a name="fitFunction">
<hr>
<h4>&fitFunction</h4>
<b>Summary:</b><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Fits the free parameters in an arbitrary function to experimental data using 
nonlinear least squares.
<p>

<b>Usage:</b><br>
&fitFunction( $dir_name, \%data, $eq, @estimates );<br>
<p>

<b>Description:</b><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
This subroutine uses the Levenburg-Marquardt algorithm to perform least
squares minimization on a supplied function.  
Adapted from Joel Tolmans "lmfit" perl scripts, and his odrfit
driver to the ODRPACK libraries.  
<p>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Fits the data found in %data to the "FORTRAN-type" equation 
supplied as $eq beginning with the estimates found in the list @estimates.  
The equation must be passed as a scaler, enclosed in
single quotes, using the following form:<br>
$eq = 'f(1,I) = b(1)*exp(-b(2)*x(I))';<br>
which would fit a 2 parameter single exponential fit.
<p>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
A directory called $dir_name is created, and contains subdirectories
named after all the atoms
found in %data hash.  Each of
these subdirectories contains XMGR files 
(use: xmgr -batch odrfit.xmgr.batch)
of the fit for that nucleus and
the actual input and output file from the odrpack fit.
<p>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
In the directory "test" will be a fit_summary.txt file which
summaries the results of the fit.

See the Netlib software repository 
<a href="http://www.netlib.org/">http://www.netlib.org/</a> 
for more details, especially the section on ODRPACK:
<a href="http://www.netlib.org/odrpack">http://www.netlib.org/odrpack/</a> 
<p>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
ODRPACK was created by<br>
Paul T. Boggs, Richard H. Byrd, 
Janet E. Rogers and Robert B. Schnabel<br> 
Center for Computing and Applied Mathematics<br>
National Institute of Standards and Technology (NIST)<br>
Gaithersburg, MD 20899
<p>

<b>Example:</b><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Fitting some experimentally measured R1 relaxation data to
2 parameter single exponential fit, the data is a list of 
3 values per data point, X1, Y1, dY1, X2, Y2, dY2, etc... 
<p>
Of course, the data can be read in from a file using the 
&readData subroutine.

<p>


<pre>
$atom = "A 1 ARG N";
$data{$atom} = [
0.00, -68.01300, 2.0,
0.25, -52.13200, 2.0,
0.50, -39.70800, 2.0,
0.75, -29.16000, 2.0,
1.00, -22.54300, 2.0,
1.25, -16.90200, 2.0,
1.50, -12.70400, 2.0,
1.75,  -9.60580, 2.0,
2.00,  -7.24160, 2.0,
2.25,  -5.47010, 2.0,
];

$debug=0;
$eq = 'f(1,I) = b(1)*exp(-b(2)*x(I))';
@est = ( 1, 1 );
%fit_data = &fitFunction( \%data, "test", $eq, @est );

($b1, $b1err, $b2, $b2err) = @{ $fit_data{$atom} };
print "b1=$b1($b1err) b2=$b2($b2err)\n";

<pre>
Which gives as a result:
<pre>
b1=-6.83877238E+01(2.7622E-01) b2=1.11536372E+00(7.6625E-03)
</pre>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Additionally, the directory yarm_work/fits/A_1_ARG_N/ contains files
with the the full statistical analysis of the fit (odrfit.out), the
original input file (odrfit.in), the original input data and the fitted 
curve (odrfit.xmgr) and an XMGR batch file to fascilitate 
visualizing the results by typing "xmgr -batch odrfit.xmgr.batch".

<p>

<!--------------------------------------------------------->
<a name="fitMultiFunction">
<hr>
<h4>&fitMultiFunction</h4>
<b>Summary:</b><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Fits the free parameters in an arbitrary function to experimental data using 
nonlinear least squares.

<b>Usage:</b><br>
&fitMultiFunction( \%data, $dir_name, \%fit_scheme );<br>
<p>

<b>Description:</b><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Works by calling fitFunction multiple times, once for each entry in %fit_scheme.
In this manner, you can automate many fitting schemes.

<b>Example:</b><br> 
<pre>
$eq = 'f(1,I) = b(1) - (b(1)-b(2))*exp(- b(3)*x(I))';
%r1_scheme = (
	"3param"   => [ "all", $eq, -0.3,	31,   1.6 ],
	"2param"   => [ "all", $eq, "0f",	 1, 	1 ],
);
%R1_raw  = &readData( $R1_raw_data );
&fitMultiFunction( \%R1_raw, "Fit_R1", \%r1_scheme );
</pre>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
This example will perform a 3 and 2 parameter fit on some R1 data, placing the
results in the subdirectory "Fir_R1", underwhich the subdirectories "3param"
and "2param" will contain the results.
