Skip to content

Instantly share code, notes, and snippets.

@aherve
Created November 23, 2016 15:15
Show Gist options
  • Select an option

  • Save aherve/3bd8652a79fafa33ef8f85e701b9421e to your computer and use it in GitHub Desktop.

Select an option

Save aherve/3bd8652a79fafa33ef8f85e701b9421e to your computer and use it in GitHub Desktop.
# derivative_scheme.(f).(x) shall be a function of epsilon
derivative_sheme = -> f {
-> x {
-> eps {
div.( minus.(plus_eps.(eps).(f), min_eps.(eps).(f) ), mult.(const.(2), const.(eps))).(x)
}
}
}
# And the derivative operator:
# Let's fix the treshold at tres = 1e-16
derivate = -> f {
-> x {
lim.(derivative_sheme.(f).(x),1,1e-16).(0) # limit of the derivative scheme of f(x), taken at epsilon = 0
}
}
# Isn't that fancy ? We juste define the derivative operator
# exactly as being the limit of (f(x + e) - f(x - e))/(2e) when epsilon -> 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment