Last active
January 1, 2016 14:49
-
-
Save metula/8160018 to your computer and use it in GitHub Desktop.
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 square(x): | |
return x**2 | |
def linear(x): | |
return 2 * x + 1 | |
def pow10(x): | |
return x**10 | |
def integral(f, h=0.001): | |
""" definite integral: function of a, b """ | |
return lambda a, b: h * sum(f(a + i * h) for i in range(0, int((b - a) / h))) | |
def integral_mid(f, h=0.001): | |
""" definite integral: function of a, b | |
considering f's value in the middle of each interval""" | |
return lambda a, b: h * sum(f(a + (i + 0.5) * h) for i in range(0, int((b - a) / h))) | |
# Derivative. | |
def diff(f, h=0.001): | |
# when h not specified, default value h=0.001 is used | |
return lambda x: (f(x + h) - f(x)) / h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment