\documentclass[a4paper,12pt]{article}
\newcommand{\ds}{\displaystyle}
\newcommand{\un}{\underline}
\parindent=0pt
\begin{document}

{\bf Question}

Calculate to 4 decimal places of accuracy

$$J=\ds\int_0^{\frac{3}{2}} \ds\frac{e^{-x}\cos x}{1+x} \,dx$$

by using

\begin{description}
\item[(i)]
the trapezium rule with 5 ordinates;

\item[(ii)]
Simpson's rule with 5 ordinates.

\item[(iii)]
Compare your answers with the exact result $J=0.439822747...$,
calculating the percentage error in each case.

\end{description}
\medskip

{\bf Answer}

$$J=\ds\int_0^{\frac{3}{2}}\ds\frac{e^{-x}\cos x}{1+x} \,dx$$

\begin{description}
\item[(i)]
Trapezium rule with 5 ordinates:

$J \approx \ds\frac{d}{2}(y_1+2y_2+2y_3+2y_4+y_5)$

where $d=\ds\frac{\frac{3}{2}}{5-1}=\ds\frac{3}{8}=0.375$

$\begin{array} {ll} x_1=0 & x_4=\ds\frac{9}{8}=1.125\\
x_2=\ds\frac{3}{8}=0.375 & x_5=\ds\frac{3}{2}=1.5\\
x_3=\ds\frac{3}{4}=0.75 \end{array}$

$$y_i=f(x_i);\ \ f(x)=\ds\frac{e^{-x}\cos x}{(1+x)}$$

\begin{tabular} {c|c|c|c|c|c|}
$x$ & 0 & 0.375 & 0.75 & 1.125 & 1.5\\

\hline

$y$ & 1.00000 & 0.46511 & 0.19750 & 0.06587 & 0.00631

\end{tabular}

\begin{eqnarray*} J & \approx &
\ds\frac{0.375}{2}(1.00000\\ & & +2\times(0.46511+0.19750 +
0.06587)+0.00631)\\ & = & \ds\frac{0.375}{2}(1.00631+1.45697)\\ &
= & \ds\frac{0.375}{2} \times 2.46328\\ & = & 0.461866\\ & = &
\un{0.4619} \end{eqnarray*}

\item[(ii)]
Simpson with 5 ordinates

$J \approx \ds\frac{h}{3}(y_1+4y_2+2y_3+4y_4+y_5)$

4 equal segments $\Rightarrow h=0.375$ as above.

So we have the same $y_i$ as above.

Hence

\begin{eqnarray*} J & \approx &
\ds\frac{0.375}{2}(1.00000+4\times(0.46511+0.06587)\\ & &
+2\times0.19750+0.00631)\\ & = & 0.125(1.00631+2.12394+0.39500)\\
& = & 0.440656\\ & = & \un{0.4407} \end{eqnarray*}

\item[(iii)]
\begin{description}
\item[(i)]
$\Rightarrow
\left|\ds\frac{exact-approx}{exact}\right|\times100=5.019=5.0\%$

\item[(ii)]
$\Rightarrow
\left|\ds\frac{exact-approx}{exact}\right|\times100=0.199=0.2\%$

So (ii), Simpson is here more accurate.

\end{description}
\end{description}
\end{document}
