On Wed, 30 Dec 2015, Riccardo (Jack) Lucchetti wrote:
On Wed, 30 Dec 2015, oleg_komashko(a)ukr.net wrote:
> We have 2 (3) ways of proceed : make experiments, find good expert on
> numerical methods (do both) The script attached shows, for small x the best
> h is as big as 10^5*sqrt($macheps) Still I do not know what to to with x:
> abs(x)>10^5 and what to do with say, exp(100) try x = {100} eval fdjac
> (x,exp(x)) - exp(100) That's ERROR! Oleh
Of course ANY numerical approximation to a derivative is a ratio; therefore,
what is crucial to its precision is the relative order of magnitude of
numerator and denominator. It's easy to contruct pathological cases and
there's no silver bullet that works in all cases.
That said, the following settings seem to work reasonably well in a
decently-sized array of cases (diff against git HEAD --- not applied yet).
<diff>
diff --git a/minpack/fdjac2.c b/minpack/fdjac2.c
index 9e9676a..54e64ec 100644
--- a/minpack/fdjac2.c
+++ b/minpack/fdjac2.c
@@ -144,10 +144,10 @@ int fdjac2_(S_fp fcn, int m, int n, int quality,
for (j = 0; j < n; j++) {
temp = x[j];
if (quality == 2) {
- if (fabs(temp) > 1000) {
- h = 1000 * sqrt(fabs(temp/1000)) * eps;
+ if (fabs(temp) > 128) {
+ h = 128* sqrt(fabs(temp/128)) * eps / sqrt(6);
} else {
- h = 1000 * eps;
+ h = 128 * eps / sqrt(6);
}
} else {
h = eps * fabs(temp);
</diff>
I'm attaching a battery of tests.
Thanks, Jack. This does look like a reasonable compromise. For ease
of experimentation I've committed a version of your patch, governed
by the BIGGER_H define (set on for the moment).
Allin