ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 10 Feb 2020 03:19:23 +0100Area under function with rectangleshttps://ask.sagemath.org/question/49856/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.Sat, 08 Feb 2020 22:45:41 +0100https://ask.sagemath.org/question/49856/area-under-function-with-rectangles/Comment by Emmanuel Charpentier for <p>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 <strong>total</strong> 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. </p>
<pre><code>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
</code></pre>
<p>Any help will be greatly apreciated.</p>
https://ask.sagemath.org/question/49856/area-under-function-with-rectangles/?comment=49862#post-id-49862Homework ?Sun, 09 Feb 2020 13:34:15 +0100https://ask.sagemath.org/question/49856/area-under-function-with-rectangles/?comment=49862#post-id-49862Comment by vdelecroix for <p>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 <strong>total</strong> 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. </p>
<pre><code>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
</code></pre>
<p>Any help will be greatly apreciated.</p>
https://ask.sagemath.org/question/49856/area-under-function-with-rectangles/?comment=49863#post-id-49863There 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]`.Sun, 09 Feb 2020 14:12:11 +0100https://ask.sagemath.org/question/49856/area-under-function-with-rectangles/?comment=49863#post-id-49863Comment by dazedANDconfused for <p>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 <strong>total</strong> 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. </p>
<pre><code>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
</code></pre>
<p>Any help will be greatly apreciated.</p>
https://ask.sagemath.org/question/49856/area-under-function-with-rectangles/?comment=49867#post-id-49867The problem your looking at is known as Riemann sums. [This Wikipedia entry](https://en.wikipedia.org/wiki/Riemann_sum) will give some insight into the functions using minimum heights as well as maximum heights. Since your function is increasing on the interval [0,6], the lower bound of the estimate for the area under the curve is from using the left endpoint. The upper bound for the estimate of the area under the curve is from using the right endpoint. The actual area under the curve will be between the left Riemann sum and the right Riemann sum.Mon, 10 Feb 2020 03:19:23 +0100https://ask.sagemath.org/question/49856/area-under-function-with-rectangles/?comment=49867#post-id-49867