Numerical integration methods

Below are scripts to compute numerical approximations to integrals via midpoint, trapezoid and Simpson's rule. You can use them for your own computations by adapting the definition of f(x), a, b, and n. These scripts are powered by Sage Cell Server. See http://www.sagemath.org for more information on the free open source mathematical software. You can download a version to run on your own computer if you want.

Midpoint rule

$$\int_a^b f(x)dx\approx \Delta \big(f(\bar{x}_1)+\cdots+f(\bar{x}_n)\big)$$ where $\Delta=\frac{b-a}{n}$ and $\bar{x}_i=a+(i+\frac{1}{2})\Delta$

Trapezoid rule

$$\int_a^b f(x)dx\approx \frac{\Delta }{2}\big(f(x_0)+2f(x_1)+\cdots+2f(x_{n-1})+f(x_n))\big)$$ where $\Delta=\frac{b-a}{n}$ and $x_i=a+i\Delta$

Simpson's rule

$$\int_a^b f(x)dx\approx \frac{\Delta }{3}\big(f(x_0)+4f(x_1)+2f(x_2)+4f(x_3)+\cdots+2f(x_{n-2})+4f(x_{n-1})+f(x_n))\big)$$ where $\Delta=\frac{b-a}{n}$ and $x_i=a+i\Delta$

Written by Nils Bruin