• API
• FAQ
• Tools
• Trends
• Archive
daily pastebin goal
4%
SHARE
TWEET

# 4H2012 lrmte.py

calcpage Apr 21st, 2013 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #!/usr/bin/python
2. from matplotlib import *
3. from pylab import *
4.
5. a=int(sys.argv[1])
6. b=int(sys.argv[2])
7. n=int(sys.argv[3])
8. f=sys.argv[4]
9.
10. def findArea(o,a,b,n,f):
11.     h=1.0*(b-a)/n
12.     x=[a+(i+o)*h for i in range(n)]
13.     y=[f(a+(i+o)*h) for i in range(n)]
14.     areas=[f(a+(i+o)*h)*h for i in range(n)]
15.     area=sum(areas)
16.     return area
17.
18. print 'n%10s %10s %10s %10s %10s' %('l', 'r', 'm', 't', 'e')
19. for x in range(5):
20.     l=findArea(0,a,b,n**x,lambda x:eval(f))
21.     r=findArea(1,a,b,n**x,lambda x:eval(f))
22.     m=findArea(0.5,a,b,n**x,lambda x:eval(f))
23.     t=(r+l)/2
24.     e=(r-l)/2
25.     print 'n**%2d %10.4f %10.4f %10.4f %10.4f %10.4f' % (x, l, r, m, t, e)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top