Skip to content

Instantly share code, notes, and snippets.

@akulakov
Created October 14, 2014 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akulakov/d133937fa28487df8b85 to your computer and use it in GitHub Desktop.
Save akulakov/d133937fa28487df8b85 to your computer and use it in GitHub Desktop.
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