The more I learn about people, the more I like dogs and I don’t even have a dog, Apocalypse, Anawim, #justtothepoint.
In analysis, numerical integration comprises a broad family of algorithms for calculating the numerical value of a definite integral.
All numerical approximations of the integral $\int_{a}^{b} f(x)dx$ will start with a partition of the interval [a, b] into n equal parts, a = x_{0} < x_{1} < ··· < x_{n} = b, Δx = x_{i}-x_{i-1}, y_{0} = f(x_{0}), y_{1} = f(x_{1}), ···, y_{n} = f(x_{n}). Loosely speaking, we want to average or add the y’s to get an approximation. We define the left Riemann sum as follows = (y_{0} + y_{1} + ··· + y_{n-1})Δx = f(x_{0})Δx + f(x_{1})Δx + ··· + f(x_{n-1})Δx = $\sum_{k=0}^{n-1} f(x_k)Δx$, and the right Riemann sum is defined similarly = (y_{1} + y_{2} + ··· + y_{n})Δx = f(x_{1})Δx + f(x_{2})Δx + ··· + f(x_{n})Δx = $\sum_{k=1}^{n} f(x_k)Δx$ -Figure 1.b.-
A trapezoid is a four-sided region with two opposite sides parallel. Given a partition of [a, b] as above, we can define the associated trapezoid sum to correspond to the area shown below. The area of a trapezoid is the average length of the parallel sides, times the distance between them, e.g., base * average_height = Δx(^{y2+y3}⁄_{2}). Adding all the areas of the individual trapezoids together, gives the trapezoid sum: $Δx(\frac{y_0+y_1}{2} + \frac{y_1+y_2}{2} + ··· + \frac{y_{n-1}+y_n}{2}) = Δx(\frac{y_0}{2} + y_1 + y_2 + ··· y_{n-1}+\frac{y_n}{2}) = \frac{left Riemann Sum + Right Riemann Sum}{2}$ -Figure 1.c.-.
Simpson’s rule gives us another approximation of the integral. Again, we start by partitioning [a, b] into intervals all of the same width, but this time we must use an even number of intervals, so n needs to be even. We are going to use a parabola through the three points (x_{k-1}, f(x_{k-1})), (x_{k}, f(x_{k})), and (x_{k+1}, f(x_{k+1})), and the area under the parabola (it is left as an exercise) equals base*average height = $2Δx(\frac{y_{k-1}+4y_k+y_{k+1}}{6})=\frac{b-a}{3n}[f(x_{k-1})+4f(x_k)+f(x_{k+1})]$, and the total sum is $\frac{Δx}{3}((y_0+4y_1+y_2) + (y_2+4y_3+y_4) + ··· (y_{n-2}+4y_{n-1}+y_n))$ = 🚀
=[🚀] $\frac{Δx}{3}(y_0 +4y_1 +2y_2 +4y_3 + ··· + 2y_{n-2}+4y_{n-1}+y_n)$ -Figure 1.d.- Here, the coefficients 1, 4, and 2 alternate. Simpson's Rule is more accurate than the trapezoidal rule for approximating integrals because it uses quadratic functions to model the curve. It provides a good balance between simplicity and accuracy for numerical integration. Futhermore, it is exact when integrating polynomials of degree 3 or less.
$\int_{1}^{2} \frac{dx}{x}= ln(x)\bigg|_{1}^{2} = ln(2) -ln(1) = ln(2) $ ≈ 0.693147 where b = x_{2} = 2, y_{2} = 2, x_{1} = 3/2, y_{1} = 2/3, a = x_{0} = 1, y_{0} = 1, b -a = 1, n = 2, $\Delta x = \frac{b-a}{n} = \frac{1}{2},$ Figure 1.a.
Trapezoidal rule. $\Delta x(\frac{1}{2}y_0 + y_1 + \frac{1}{2}y_2)=\frac{1}{2}(\frac{1}{2})·1 + \frac{2}{3} + \frac{1}{2}·\frac{1}{2}$ ≈ 0.96 it is obviously not a good approximation 😞, but it was expected we should split the interval into more subintervals.
Sympson’s rule. $\frac{\Delta x}{3}(y_0 +4y_1 +y_2) = \frac{1}{6}(1 + 4·\frac{2}{3}+\frac{1}{2}) ≈ 0.69444$ that is surprisingly a relatively good approximation of the correct value.
$\int_{-∞}^{∞} e^{-t^{2}}dt$ =[Recall F(x) = $\int_{0}^{x} e^{-t^{2}}dt$] 2F(∞) =[F(∞)=$\frac{\sqrt{π}}{2}$] $\sqrt{π}$ -Figure 1.b.-.
Volume of the function 0 < y < x rotated around y-axis, $\int_{0}^{1} 2π(x-x^3)dx = π(x^2-\frac{x^4}{2})\bigg|_{0}^{1} = π(1-\frac{1}{2}) = \frac{π}{2},$ Figure 1.c.