Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better precision in divided differences #404

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Smearing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ function occupation_divided_difference(S::SmearingFunction, x, y, εF, temperatu
end
end
function divided_difference_(f, fder, x, y)
# This is only accurate to sqrt(ε)
abs(x-y) < sqrt(eps(typeof(x))) && return fder((x+y)/2)
# (f(x) - f(y))/(x - y) is accurate to ε/|x-y|
# so for x ~= y we use the approximation (f'(x)+f'(y))/2,
# which is accurate to |x-y|^2, and therefore better when |x-y| ≤ cbrt(ε)
# The resulting method is accurate to ε^2/3
abs(x-y) < cbrt(eps(typeof(x))) && return (fder(x) + fder(y))/2
(f(x)-f(y)) / (x-y)
end

Expand Down