% This is lecture no. 16 of MH1101/: Calculus II.

\chapter{Simpson's Rule}%
\label{cha:simpson_s_rule}

\section{General Formula}%
\label{sec:general_formula}

Simpson's Rule is a weighted average of the Trapezoidal and Midpoint Rules.
It assumes that $n$ is even and that:
\[
S_n = \frac{1}{3}T_{n/2}+\frac{2}{3}M_{n/2}
.\]
To define both $T_{n/2}$ and $M_{n/2}$ we consider again dividing the interval $[a,b]$ into $n$ subintervals:
\[
	[x_0,x_1],[x_1,x_2],\dotsc,[x_{n-1},x_n]
.\]
Then, we consider the following subintervals:
\[
	[x_0,x_2],[x_2,x_4],\dotsc,[x_{n-2},x_n]
.\]
The endpoints of these subintervals $x_0,x_2,\dotsc,x_{n-2},x_n$ are used to compute $T_{n/2}$:
\begin{align*}
	T_{n/2} & = \frac{1}{2}\frac{b-a}{n/2}(f(x_0)+2f(x_2)+2f(x_4)+\dotsb+2f(x_{n-2})+f(x_n))\\
		& = \Delta x(f(x_0)+2f(x_2)+2f(x_4)+\dotsb+2f(x_{n-2})+f(x_n))
\end{align*}
The midpoints of the subintervals $x_1,x_3,\dotsc,x_{n-3},x_{n-1}$ are used to compute $M_{n/2}$:
\begin{align*}
	M_{n/2} & = \frac{b-a}{n/2}(f(x_1)+f(x_3)+\dotsb+f(x_{n-3})+f(x_{n-1}))\\
		& = \Delta x(2f(x_1)+2f(x_3)+\dotsb+2f(x_{n-3})+2f(x_{n-1}))
\end{align*}
Combining the two we get:
\[
	S_n = \frac{1}{3}\Delta x(f(x_0)+4f(x_1)+2f(x_2)+\dotsb+2f(x_{n-2})+4f(x_{n-1})+f(x_n))
.\]
\begin{exmp}
	Use Simpson's Rule with $n=8$ to find $\displaystyle{\int_{2}^{4} \sqrt{1+x^3} \ud x}$.
	\begin{sol}
		We have:
		\[
		\Delta x= \frac{b-a}{n}= \frac{4-2}{8}=0.25
		,\]
		and therefore we have:
		\begin{center}
			\begin{tabular}{c | c | c | c| c| c| c| c| c}
				$x_0$ & $x_1$ & $x_2$ & $x_3$ & $x_4$ & $x_5$ & $x_6$ & $x_7$ & $x_8$\\
				\hline
				2 & 2.25 & 2.5 & 2.75 & 3 & 3.25 & 3.5 & 3.75 & 4\\
			\end{tabular}
		\end{center}
		Now, let:
		\[
			f(x) = \sqrt{1+x^3}
		.\]
		Thus:
		\begin{IEEEeqnarray*}{rCl}
			S_8 & = & \frac{1}{3}(0.25)(f(x_0)+4f(x_1) + 2f(x_2)+4f(x_3)+2f(x_4) \nonumber\\
			    && \negmedspace{} +4f(x_5)+2f(x_6) + 4f(x_7) + f(x_8))\\
			    & = & \frac{1}{12}\left(\sqrt{1+2^3}+4\sqrt{1+2.25^3}+2\sqrt{1+2.5^3}+4\sqrt{1+2.75^3}\right.\nonumber\\
			    && \negmedspace{} +2\sqrt{1+3^3}+4\sqrt{1+3.25^3}+2\sqrt{1+3.5^3}\nonumber\\
			    && \left.\negmedspace{} + 4\sqrt{1+3.75^3}+\sqrt{1+4^3}\right)\\
			    & \approx & \frac{1}{12}(3 + 4(3.52003) + 2(4.07738) + 4(4.66871) + 2(5.2915)\nonumber\\
			    && \negmedspace{} +4(5.94375) + 2(6.62382) + 4(7.33037) + 8.06226)\\
			    & \approx & 10.74159.
		\end{IEEEeqnarray*}
		As required.
	\end{sol}
\end{exmp}

\section{Error Bounds}%
\label{sec:error_bounds}

Error bounds for the trapezoidal and midpoint rule rely on finding the second derivative of the integrand, however, error bounds for Simpson's rule depends on the fourth derivative of the function.

\begin{thrm}
	Error Bound for Simpson's Rule.
	Suppose that $|f^{(4)}(x)|\leqslant K$ for all $a\leqslant x\leqslant b$.
	If $E_S$ is the error involved in using the Simpson's Rule, then:
	\[
		|E_S| \leqslant \frac{K(b-a)^{5}}{180n^{4}}
	.\]
\end{thrm}
\begin{exmp}
	Find $n$ such that $S_n$ has an absolute error of at most $10^{-6}$ for the following:
	\[
		S_n \approx \int_{1}^{3} \frac{1}{x} \ud x
	.\]
	\begin{sol}
		Let $\displaystyle{f(x)=\frac{1}{x}}$, then:
		\[
			f^{(4)}(x) = 24x^{-5}
		,\]
		which is decreasing, so its maximum on $[1,3]$ is $f^{(4)}(1)=24$.
		Thus we choose $K=24$, and by using the error bound theorem we see that:
		\[
			|E_S|\leqslant \frac{24(3-1)^{5}}{180n^{4}} = \frac{64}{15n^{4}}
		.\]
		To ensure that the error is at most $10^{-6}$, we choose $n$ so that:
		\[
		|E_S|\leqslant \frac{64}{15n^{4}}\leqslant 10^{-6}
		.\]
		Which is true iff:
		\begin{align*}
			n^{4} & \geqslant 10^{6}\left(\frac{64}{15}\right)\\
			\therefore n & \geqslant \left(10^{6}\left(\frac{64}{15}\right)\right)^{\frac{1}{4}}\\
				     & \approx 45.45.
		\end{align*}
		Thus, we should take $n=46$ which works out perfectly since our choice for $n$ has to be even for Simpson's Rule.
	\end{sol}
\end{exmp}
