\section{FITFUN Fit a Function}

\subsection{Usage}

Fits \verb|n| (non-linear) functions of \verb|m| variables using least squares
and the Levenberg-Marquardt algorithm.  The general syntax for its usage
is
\begin{verbatim}
  [xopt,yopt] = fitfun(fcn,xinit,y,weights,tol,params...)
\end{verbatim}
Where \verb|fcn| is the name of the function to be fit, \verb|xinit| is the
initial guess for the solution (required), \verb|y| is the right hand side,
i.e., the vector \verb|y| such that:
\[
   xopt = \arg \min_{x} \|\mathrm{diag}(weights)*(f(x) - y)\|_2^2,
\]
the output \verb|yopt| is the function \verb|fcn| evaluated at \verb|xopt|.  
The vector \verb|weights| must be the same size as \verb|y|, and contains the
relative weight to assign to an error in each output value.  Generally,
the ith weight should reflect your confidence in the ith measurement.
The parameter \verb|tol| is the tolerance used for convergence.
The function \verb|fcn| must return a vector of the same size as \verb|y|,
and \verb|params| are passed to \verb|fcn| after the argument \verb|x|, i.e.,
\[
  y = fcn(x,param1,param2,...).
\]
Note that both \verb|x| and \verb|y| (and the output of the function) must all
be real variables.  Complex variables are not handled yet.
