Created
October 14, 2014 20:13
-
-
Save akulakov/d133937fa28487df8b85 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 bitfunc(x): | |
return x**4 - 5 * x**2 + 4 | |
def bitfunc_rect(x1, x2): | |
# print("bitfunc_rect ", x1, x2) | |
return (x2-x1) * bitfunc(x1) | |
def bitfunc_recur(steps, x1, x2): | |
if steps: | |
step = (x2-x1) / steps | |
return bitfunc_rect(x1, x1+step) + bitfunc_recur(steps-1, x1+step, x2) | |
else: | |
return 0 | |
def bitfunc_iter(steps, x1, x2): | |
step = (x2-x1) / steps | |
area = 0 | |
for n in range(steps): | |
area += bitfunc_rect(x1, x1+step) | |
x1 += step | |
print("x1", x1) | |
return area | |
# print(bitfunc_recur(5,5,10)) | |
# print(bitfunc_iter(5,5,10)) | |
def compare(*args): | |
return abs(bitfunc_recur(*args) - bitfunc_iter(*args)) | |
# print(bitfunc_recur(11, 5, 10)) | |
# print(bitfunc_iter(11, 5, 10)) | |
# print(compare(110, 5, 10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment