Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from matplotlib import *
- from pylab import *
- a=1
- b=5
- n=8
- h=1.0*(b-a)/n
- def f(x):
- return x**2
- x=[a+i*h for i in range(n)]
- y=[f(a+i*h) for i in range(n)]
- areas=[f(a+i*h)*h for i in range(n)]
- area=sum(areas)
- print "x=",x
- print "y=",y
- print "areas=",areas
- print "area=",area
- plot(x,y,color='red')
- for i in range(n):
- matplotlib.pyplot.gca().add_patch(matplotlib.patches.Rectangle((a+i*h,0),h,f(a+i*h)))
- show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement