Created
July 23, 2008 05:02
-
-
Save lutzky/1534 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Epsilon = 1e-10 | |
def d_dx(&f) # :yields: x | |
Proc.new do |x| | |
(f[x + Epsilon] - f[x])/Epsilon | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'derivative' | |
if __FILE__ == $0 | |
puts "Derivation example: g is the derivative of x**2" | |
g = d_dx { |x| x**2 } | |
puts "g[8] is #{g[8]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment