,
,
the initial starting point for the fit
,
, and the error
matrices
and
.
There's also a constraint function constraint_fcn,
which takes a point
,
and returns
the values of the constraints
and their gradients
and
.
and
to get the initial values for
,
, and
. If the initial starting point is rejected
by constraint_fcn as invalid, return an error status.
-
and
-
.
,
, and
-
.
for
and
. Also remember the matrices
,
, and
, defined by the equations
.
and
by
and
.
In case the step needs to be cut, compute the value of
by
.
,
,
by
+
and
+
.
.
,
.
If constraint_fcn rejects the point, the step must be cut,
as described below. Compute the sum of the absolute values of the
constraint functions, constraint_sum.
If it has decreased since the last step, or if it is
below the convergence threshold constraint_sum_eps, the step
is accepted. The first step is accepted no matter what the
constraint functions are doing. Otherwise, the constraints have
increased, and the step should be cut:
is stationary.
If
, try
a directed step:
for
and
, using the values of
and
from
the beginning of the step. Also remember
,
, and
,
as before.
.
+
+
and
+
+
.
,
is an acceptable point
and the value of constraint_sum is now less
than the value on the previous step, then
accept the directed step and make the assignments
-
- 
Otherwise, continue with the attempt to cut the step.
.
Normally, this is set to a constant cutsize. However, it is fairly
common to have a number of steps in a row, all of which get cut to about
the same size. To speed up this case, remember the total cut size from
the last step. If this is the first cut for this step,
and the last step was also cut, set
to twice the
final cut size from the last step, provided that this value is less
than cutsize.
.
If the total cut size falls below a threshold,
, give up and
return an error.
and
.
and
from (A.56) and
(A.58), and the new
and
from
+
and
+
.

and
for two iterations in a row. If these conditions are satisfied,
exit the fit loop and go to step 15.
and
from (A.38) and (A.40), and the vectors
of pull functions
and
from
(A.48) and (A.50).