SHARE
TWEET

2016AB1BC1.py

calcpage Jun 23rd, 2016 790 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. #MrG 2016.0621 2016AB1BC1
  3. #1c) 49786 l
  4. import math
  5. f="2000*math.exp(-x**2/20)"
  6. a=float(0)
  7. b=float(8)
  8. n=10
  9.  
  10. def lSum(f,a,b,n):
  11.     h=(b-a)/n
  12.     return sum([f(a+i*h)*h for i in range(n)])
  13.  
  14. def rSum(f,a,b,n):
  15.     h=(b-a)/n
  16.     return sum([f(a+i*h)*h for i in range(n)])-f(a)*h+f(b)*h
  17.  
  18. print "l\t\tr\t\tt"
  19. for j in range(4):
  20.     n=10**j
  21.     l=50000-8050+lSum(lambda x: eval(f),a,b,n)
  22.     r=50000-8050+rSum(lambda x: eval(f),a,b,n)
  23.     print l,"\t",r,"\t",(r+l)/2
RAW Paste Data
Top