|
Contents | Previous | Next | Subchapters |
| Syntax |
testder(function fval, x0, h) |
| See Also | testgrad , testhess |
f(x),
testder compares this calculation
with a central difference approximation.
The results of the comparison are printed in the command window.
The column vector x0 specifies
the value of x at which to check the calculation of the derivative.
The column vector h
has the same type and dimension as x0. It specifies the
step size to use for each component of x when
computing the central difference approximations to the
derivative of f(x).
fval(x1, fout)
fval(x1, fout, dfout)
The column vector x1
has the same type and dimension as x0 and specifies
a point at which to calculate the value of f(x).
The input value of fout
does not matter. Its output value is a
column vector with the same type as x0
and equal to the value of f(x1).
If dfout is present, its input value does not matter.
Its output value is a matrix with the same type and
row dimension as fout.
Its column dimension is equal to the
row dimension of x1 and
d f (x) |
i |
dfout = -------- |
i,j d x | x = x1
j
For each component of x,
the partials returned by fval,
the central difference approximation,
and the corresponding relative error are printed in the command window.
f(x) where
/ x \ d f(x) | / 1 \
f(x) = | | , ------ | = | |
\ x^2 / d x |x = 1 \ 2 /
clear
function fval(x1, fout, dfout) begin
fout = {x1, x1^2}
if arg(0) == 3 then ...
dfout = {1, 2 * x1}
end
x0 = 1.
h = .001
testder(function fval, x0, h)