We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9b51a54 commit 51d10e9Copy full SHA for 51d10e9
src/semidiscretization/semidiscretization.jl
@@ -240,7 +240,12 @@ function jacobian_fd(semi::AbstractSemidiscretization;
240
# use second order finite difference to estimate Jacobian matrix
241
for idx in eachindex(u0_ode)
242
# determine size of fluctuation
243
- epsilon = sqrt(eps(typeof(u0_ode[idx])))
+ # This is the approach used by FiniteDiff.jl to compute the
244
+ # step size, which assures that the finite difference is accurate
245
+ # for very small and very large absolute values `u0_ode[idx]`.
246
+ absstep = sqrt(eps(typeof(u0_ode[idx])))
247
+ relstep = absstep
248
+ epsilon = max(relstep * abs(u0_ode[idx]), absstep)
249
250
# plus fluctuation
251
u_ode[idx] = u0_ode[idx] + epsilon
0 commit comments