I was trying to derive limit form of integral and I got the below. But I'm not sure what is wrong about it. I learned about it in class today and I'm having all the rectangles under a function summed since the width can be defined by $b/r$ and the height can be $f(bx/r)$
$$\int_{0}^{b} f(x) \,dx = \lim_{r \to \infty} \left(\sum_{k=0}^{r-1} \frac{b}{r}f\left(\frac{bk}{r}\right)\right)$$
Here I am setting $r$ to the number of rectangles (it approaches infinity), $f$ is the function and inside the summation it slowly sums each value until $b$ is reached.
I even tried running it using Python and it seems to work correctly for the basic functions I've tried
def calculate_limit(f, r):
total = 0
for x in range(r + 1):
total += a/r * f(x*a / r)
return total
def f(x):
return x**2
r = 1000
a = 2
limit = calculate_limit(f, r)
print(limit)
```
(This is a community wiki answer! Please feel free to improve it to your liking.)
Nice self discovery!
Indeed there is no particularly wrong part of your discovery. The equality holds if $f$ is continuous (or even Riemann integrable) on the interval $[0, b]$:
\begin{align*} \int_{0}^{b} f(x) \, \mathrm{d}x &= \lim_{n\to\infty} \sum_{k=1}^{n} f\left(\frac{kb}{n}\right)\frac{b}{n} \tag{1}\\ &= \lim_{n\to\infty} \sum_{k=0}^{n-1} f\left(\frac{kb}{n}\right)\frac{b}{n} \tag{2} \end{align*}
Remarks:
In $\text{(1)}$, the right endpoint of the subinterval is used to calculate the height of each rectangle, whereas in $\text{(2)}$, the left endpoint is used.
Although the above equality is enough to establish a theoretical definition of a (rudimentary version of) definite integral, you may have already noticed that the approximation still deviates from the actual value even when the number $n$ of divisions is large. This opens up the question that eventually leads us to the area of numerical integration, where a much more efficient ways of approximating integrals has been studied.
I also brushed up your code for fun: