SHARE
TWEET

4H2012 lsumtable.py

calcpage Apr 19th, 2013 34 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. a=2
  3. b=9
  4. def f(x):
  5.     return x**3
  6.  
  7. #print "h = ", h
  8. #print range(n)
  9. #print [i for i in range(n)]
  10. #print [i*h for i in range(n)]
  11. #print [a+i*h for i in range(n)]
  12. #print [f(a+i*h) for i in range(n)]
  13. #print [f(a+i*h)*h for i in range(n)]
  14. #print sum([f(a+i*h)*h for i in range(n)])
  15.  
  16. print "n\tlsum(n)"
  17. for x in range(6):
  18.     h=1.0*(b-a)/10**x
  19.     print "10**",x,"\t",sum([f(a+i*h)*h for i in range(10**x)])
RAW Paste Data
Top