Open JianghuiDu opened 5 years ago
Are you sure there's a soluble mistake here? Reasoning based on this specific example doesn't seem like it will provide you with a totally reliable debugging strategy. I'd suggest doing some quick reading of the literature on epsilon-selection rules to understand how people reason about this space and the trade-offs involved.
As an example of how it's useful to take a broader view here, using eps()
would often not work well because of rounding errors. The Wikipedia section is good on this: https://en.wikipedia.org/wiki/Numerical_differentiation#Practical_considerations_using_floating-point_arithmetic
The rules we use are stated here: https://scicomp.stackexchange.com/a/14357 The link to Numerical Recipes will point you to a longer discussion of the topic.
I think there is a problem with the
central
difference code. Here is a simply example:We know that the analytical derivative is
which at
x=2e-8
is3.137210795286552e6
, similar to theforward difference
result (at least on the same order of magnitude) but there is a 5 orders of magnitude difference compared to thecentral difference
result, which is supposed to be2nd
order accurate! I looked through the source code, and I think the problem is with the macro@centralrule
in comparison
The stepping given by
@centralrule
is clearly unacceptably large (2 orders of magnitude greater thanx
!. I don't quite understand why the stepping in the@centralrule
is taken as the cubic square root ofeps()
while the@forwardrule
uses the square root ofeps()
?In this case an appropriate stepping show be smaller than the order of
1e-10
, which nether of these two methods gives. Why not just useeps()
as the step size?