On Mon, 16 Oct 2017, Berend Hasselman wrote:
See "The Complex-Step Derivative Approximation" in
ACM Transactions on Mathematical Software, Vol. 29, No. 3, September 2003, Pages
245–262.
and the Reference manual of the R numDeriv package
(
https://cran.r-project.org/web/packages/numDeriv/numDeriv.pdf)
assuming that Gretl is not using the complex step method.
And assuming that the functions to be differentiated can handle complex values.
Thanks, Berend, this is very helpful. The complex-step derivative looks
very cool. It can certainly be very useful in many cases. However, it
requires the function to be differentiated to (i) make sense for
complex values and (ii) to have an internal function that performes the
evaluation of the complex function; this complicates things quite a bit
for user-written functions.
Besides, the quality of the result is comparable to what we already get
via Richardson extrapolation. The complex-step technique performs a
second-order approximation, which is what we get by setting fdjac_quality
to 2. For example, try the following script (which uses the definition of
rderiv as per Oleh's previous script):
<hansl>
set verbose off
function scalar cube(matrix *x)
return x[1]^3
end function
g = rderiv("x^3", 0)
printf "rderiv: %36.33f\n", g
x = {0}
set fdjac_quality 1
g = fdjac(x, cube(&x))
printf "fdjac(1): %36.33f\n", g
set fdjac_quality 2
g = fdjac(x, cube(&x))
printf "fdjac(2): %36.33f\n", g
</hansl>
On my system I get
<output>
rderiv: -0.000000000000000000000000000000049
fdjac(1): 0.000000000000000888178419700125430
fdjac(2): 0.000000000000000000000000000000000
</output>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------