You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
which at x=2e-8 is 3.137210795286552e6, similar to the forward difference result (at least on the same order of magnitude) but there is a 5 orders of magnitude difference compared to the central difference result, which is supposed to be 2nd order accurate!
I looked through the source code, and I think the problem is with the macro @centralrule
The stepping given by @centralrule is clearly unacceptably large (2 orders of magnitude greater than x!. I don't quite understand why the stepping in the @centralrule is taken as the cubic square root of eps() while the @forwardrule uses the square root of eps()?
macro forwardrule(x, e)
x, e = esc(x), esc(e)
quote
$e = sqrt(eps(eltype($x))) * max(one(eltype($x)), abs($x))
end
end
macro centralrule(x, e)
x, e = esc(x), esc(e)
quote
$e = cbrt(eps(eltype($x))) * max(one(eltype($x)), abs($x))
end
end
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 use eps() as the step size?
The text was updated successfully, but these errors were encountered:
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.
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?The text was updated successfully, but these errors were encountered: