Created
July 7, 2019 17:48
-
-
Save Demonstrandum/3591116dd1aaca936f272c994cc17675 to your computer and use it in GitHub Desktop.
Helping Sam Frost
This file contains 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
def f x; x**2 + 2*x + 1; end | |
def integrate sym, a, b | |
dx = 0.001 | |
fn = method sym | |
dx * (a..b - dx).step(dx).map(&fn).sum | |
end | |
puts integrate :f, 2, 4 | |
def differentiate sym, x | |
h = 0.001 | |
fn = method sym | |
(fn.call(x + h) - fn.call(x)) / h | |
end | |
puts differentiate :f, 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hai