\documentclass[a4paper,12pt]{article}
\newcommand{\ds}{\displaystyle}
\newcommand{\un}{\underline}
\parindent=0pt
\begin{document}

{\bf Question}

Calculate

$$ J=\ds\int_0^1 \ds\frac{\cos x}{1+x^2} \,dx$$

by using

\begin{description}
\item[(i)]
the trapezium rule with 7 ordinates,

\item[(ii)]
Simpson's rule with 7 ordinates.

\end{description}

Compare your answers with the exact result $J=0.6829....$


\medskip

{\bf Answer}

$$J=\ds\int_0^1 \ds\frac{\cos x}{(1+x^2)} \,dx$$

\begin{description}
\item[(i)]
Trapezium rule with 7 ordinates:

$J \approx \ds\frac{d}{2}(y_1+2y_2+2y_3+2y_4+2y_5+2y_6+y_7)$

where $d=\ds\frac{1-0}{7-1}=\ds\frac{1}{6}$

$\begin{array} {ll} x_1=0 & x_4=\ds\frac{3}{6}\\
x_2=\ds\frac{1}{6} & x_5=\ds\frac{4}{6}\\ x_3=\ds\frac{2}{6} & x_6
\ds\frac{5}{6}\\ & x_7=2 \end{array}$


$$y_i=f(x_i);\ \ f(x)=\ds\frac{\cos x}{1+x^2}$$

\begin{tabular} {c|c|c|c|c|c|c|c|}
$x$ & 0 & $\frac{1}{6}$ & $\frac{1}{3}$ & $\frac{1}{2}$ &
$\frac{2}{3}$ & $\frac{5}{6}$ & 1\\

\hline

$y$ & 1.0 & 0.95949 & 0.85046 & 0.70207 & 0.54408 & 0.39683 &
0.27015\\

\end{tabular}

$J \approx \ds\frac{1}{12}(1.0+2
\times[0.95949+0.85046+0.70207+0.54408+0.39683]+0.27015)$

\newpage
\begin{eqnarray*} J & \approx &
\ds\frac{1}{12}(1.27015+2\times3.45293)\\ & = &
\ds\frac{1}{12}(1.27015+6.90586)\\ & = &
\ds\frac{1}{12}(8.17601)\\ & = & \un{0.681334...} \end{eqnarray*}

\item[(ii)]
Simpson's rule with 7 ordinates:

$J \approx \ds\frac{d}{2}(y_1+4y_2+2y_3+4y_4+2y_5+4y_6+y_7)$

6 equal segments $\Rightarrow h=\ds\frac{1}{6}$

so we have the same $y_i$ as above.

Hence

\begin{eqnarray*} J & \approx & \ds\frac{1}{18}(1.0+4
\times(0.95949+0.70207+0.39683)\\ & &
+2\times(0.85046+0.54408)+0.27015)\\ & = &
\ds\frac{1}{18}(1.27015+0.823356+2.78908)\\ & = & \ds\frac{1}{18}
\times 12.2928\\ & = & \un{0.682933...}
\end{eqnarray*}

Actual=0.6829 to 4sf

\begin{description}
\item[(i)]
is accurate to 0.2\% or 2sf

\item[(ii)]
is accurate to 4sf
\end{description}


\end{description}

\end{document}
