# Area under function with rectangles

I'm assigned to write a simple function which gives me the area under x^4 between an interval, but using a series of rectangles instead of a straight integral. I have to write a function that defines the minimum height of these rectangles and another function defining the maximum height, and then find the average value. I am a total newbie, so as trivial as it sounds, I've no clue how to define those functions. I dont know how to make one define minimum heights and the other define maximum, and I don't think what I came up with as a sum of rectangles is correct.

def Smin(n):
sum=0
a=0
b=6
width=(b-a)/n
for i in range (1,n+1):
sum=width*(sum+i**4)
return sum


Any help will be greatly apreciated.

edit retag close merge delete

There are several problems with your function. It takes n as an arguemt (def Smin(n)) but where do a and b come from? Don't you want to make them argument as well?
On the other hand, if you want to integrate x^4 on the interval [a, b], this is not what your function is doing. What you want to do is something like $h \times \sum_{i=0}^{n} (a + i h)^4$. You should first fix your Smin function (and check that it works). Then, you will be able to improve it by computing lower and upper bounds for the integral using minimum and maximal value inside an interval [a + ih, a + (i+1)h].