|
Contents | Previous | Next | Subchapters |
| Syntax |
dnlsq(function fval, xini, scale, eps, maxit, level) |
| See Also | nlsq , dnlsqb |
2
minimize |f(x)| with respect to x.
If analytic derivatives of f(x) are not available,
the function nlsq
can be used to solve this problem.
scale(i) is the maximum absolute change in x(i)
per iteration.
Every element of scale must be greater than 0.
x(i)
is less than eps times scale(i) for all i.
dnlsq.
If level > 1, the value of |f(x)|^2 is printed
at each iteration.
fval(x, fout)
the vector x
has the same type and dimension as xini
and specifies the point at which to evaluate f(x).
The input value of fout has no effect,
and its output value is the value of f(x)
as a column vector with the same type as x.
fval(x, fout, dfout)
the arguments x and fout have the same meaning as
above.
The input value of dfout
has no effect and its output value is the derivative of
f with respect to x and has the same type and row
dimension as fout and a column dimension equal to the
row dimension of x.
The (i,j)-th element of dfout is the derivative of the
i-th component of f(x) with respect to the
j-th component of x.
x at the i-th iteration.
(The first column contains the initial value of x.)
The return value has same type and row dimension as xini.
Its column dimension is equal to the number of iterations plus 1.
10
----- 2
minimize > [ x exp(- x t ) - y ] with respect to x
----- 1 2 i i
i = 1
where
y = .5 exp(- t ) and t = i / 10
i i i
The solution is x = {.5, 1.}.
clear
#
const t = seq(10) / 10.
const y = .5 * exp(-t)
#
function fval(x, fout, dfout) begin
#
fout = x(1) * exp(-x(2) * t) - y
if arg(0) < 3 then return
#
d1 = exp(-x(2) * t)
d2 = -x(1) * exp(-x(2) * t) % t
dfout = [d1, d2]
end
xini = {2., 2.}
scale = {.5, .5}
eps = 1e-4
maxit = 10
level = 0
x = dnlsq(function fval, xini, scale, eps, maxit, level)
xout = x.col(coldim(x))
print xout