Contents Previous Next Subchapters

Nonlinear Least Squares With Box Constraints and Derivatives
Syntax dnlsqb(function fvalxinixlowxupdeltamaxitlevel)
See Also nlsqbox , linlsqb

Description
Uses the Gauss-Newton method to solve the problem
     minimize  |f(x)|^2 with respect to x 
     such that xlow <= x <= xup
The return value of dnlsqb is a value of x that approximates the solution of the optimization problem. The return value has the same type and dimension as xini.

The function calls fval(xf_out) and fval(xf_outdf_out) evaluate f(x) and its derivative. The vector x has the same type and dimension as xini. It specifies the point at which to evaluate f(x). The input value of f_out does not matter. Its output value is f(x) as a column vector with the same type as x. If df_out is present, its input value does not matter. Its output value is the derivative of f(x) as a matrix with the same type and row dimension as f_out, and column dimension equal to the row dimension of x. The element df_out(ij) is the derivative of the i-th component of f(x) with respect to the j-th component of x.

The real or double-precision column vector xini specifies the point at which to start the Gauss-Newton method. The a column vector xlow has the same type and dimension as xini. It specifies the lower limit for the minimization problem. The a column vector xup has the same type and dimension as xini. It specifies the upper limit for the minimization problem. The scalar delta has the same type as xini. Convergence is accepted if for each i,
     |x(i) - xmin(i)| < delta * (xup(i) - xlow(i))
where xmin is a minimizer of the objective function. Convergence is also accepted is the absolute change in |f(x)|^2 is less than delta times its value. The integer scalar maxit specifies the maximum number of iterations to try before giving up on convergence.

The integer scalar level specifies the level of tracing inside of dnlsqb. If dnlsqb fails to converge, the message "dnlsqb failed to converge" is printed. If level > 1, the messages "begin dnlsqb" is printed before the first iteration and if the method converges, "dnlsqb converged" is printed at the end. In addition, the value of |f(x)|^2 is printed at each iteration. If level > 2, the value of x is printed at each iteration.

Example
The example below solves the problem
     minimize [exp(x(1)) - exp(1.)]^2 + [exp(x(2)) - exp(2.)]^2
     with respect to x such that
     -1 < x(1) < +1
     -1 < x(2) < +1
The solution to this problem is x(1) = 1 and x(2) = 1.

clear
function fval(x, f_out, df_out) begin
     f_out = {exp(x(1)) - exp(1.), exp(x(2)) - exp(2.)}
     if arg(0) >= 3 then ...
          df_out = diag(exp(x))
end
xini   = {  0.,  0.} 
xlow   = { -1., -1.} 
xup    = { +1., +1.} 
delta  = 1e-4
maxit  = 10
level  = 2
argmin = dnlsqb(function fval, xini, xlow, xup, delta, maxit, level)
print "argmin' =", argmin'