An archived instance of discourse for discussion in undergraduate Real and Numerical Analysis.

A trapezoidal sum

mark

Suppose we wish to estimate $$\int_0^2 e^{-x^2} dx$$ with a trapezoidal sum and we'd like our result to be within $0.0001$ of the actual value.

• Find an $n$ large enough so that $n$ terms will guarantee your estimate is within the desired accuracy.
• Write down the resulting sum using summation notation.

Note: The graphs of $f$ and $f''$ are shown below.

gbrock

When using trapezoidal sums, we can say: $$\int_{a}^{b} f(x) dx \approx T_{n} = \sum_{i=1}^{n} \dfrac{f(x_{i})+f(x_{i-1})}{2} \Delta x$$
If we let $I$ be the true value of the integral, then the error between the real solution and the trapezoidal sum is given by $\left| I - T_{n}\right|$. Through a long complicated process, we can also say the following is true:
$$\left| I - T_{n}\right| \leq \dfrac{D}{12} \dfrac{(b-a)^{3}}{n^{2}}$$ where $D$ is a bound on $f^{''}$ over $[a,b]$ and $n$ is the number of partitions used in the sum.


For this problem specifically, we want $\left| I - T_{n} \right| < 0.0001$, meaning we want $\frac{D}{12} \frac{(2-0)^{3}}{n^{2}} < 0.0001$ In order to solve for $n$, we need to find a value for $D$. A quick glance at the graph above shows $2.5$ to be a fine choice for $D$. Armed with $D = 2.5$, we can say $$\left| I - T_{n}\right| \leq \dfrac{2.5}{12} \dfrac{(2-0)^{3}}{n^{2}} < 0.0001$$ which gives us $n >129$. So $n=130$ should give an estimate within the desired accuracy.


Moving on to the sum, recall from earlier that $T_{n} = \sum_{i=1}^{n} \dfrac{f(x_{i})+f(x_{i-1})}{2} \Delta x$. Note $\Delta x = \frac{b-a}{n} = \frac{2}{130}$ and $x_{i} = a + i \Delta x = 0 + \frac{2i}{130}$. Thus,

$$\int_{0}^{2} e^{-x^{2}} dx \approx \sum_{i=1}^{130} \dfrac{e^{-\left(\frac{2i}{130}\right)^{2}}+e^{-\left(\frac{2(i-1)}{130}\right)^{2}}}{130}$$.

Let me know if anything seems wrong here. I was frustrated by the lack of a Latex preview while typing all that out and probably made numerous mistakes...

mark

@gbrock I think this looks great! Note that you can implement it too:

In[]: sum([(np.exp(-(2*i/130)**2)+np.exp(-(2*(i-1)/130)**2))/130 \
for i in range(1,131)])
Out[]: 0.88207994579860516

We'll compare that against SciPy's numerical integrator in class and see how it looks.

Also, I agree that the LaTeX preview thing is a pain - you did quite admirably. Note that the reload trick does help, even while in the middle of an edit. I guess that should help some, at least.