Skip to content

Instantly share code, notes, and snippets.

@askn
Created May 15, 2013 03:00
Show Gist options
  • Save askn/5581374 to your computer and use it in GitHub Desktop.
Save askn/5581374 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def f(x):
return x ** 2
def main(x, y, n):
aralik = float(y - x) / n
L = 0
U = 0
for i in range(n):
L += f(x) * aralik
x += aralik
U += f(x) * aralik
print L, U
if __name__ == '__main__':
main(0, 1, 10)
main(0, 1, 100)
main(0, 1, 1000)
# 0.285 0.385
# 0.32835 0.33835
# 0.3328335 0.3338335
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment