User:Egm6341.s10.team3.sa/HW2

HW Problem Set 2

=Equivalence between an $$n^{th}$$  order polynomial and Lagrange interpolation polynomial= Ref: Lecture notes [[media:Egm6341.s10.mtg8.pdf|p.8-3]]

Problem Statement

 * {| style="width:100%" border="0" align="left"

$$\displaystyle where\, c_0,\, c_1\,and\,  c_2\,  are\, constants.$$ $$\displaystyle P_2(x) = \sum_{i=0}^{2} l_i(x) f(x_i)$$ $$\displaystyle Find\, the\,  coefficients\,  c_i\, in\, terms\,  of\,  x_i\, and\,  f(x_i)\;\; i=0,1,2. $$
 * $$\displaystyle f_2(x) = P_2(x) = c_0 + c_1x + c_2x^2 $$
 * $$\displaystyle f_2(x) = P_2(x) = c_0 + c_1x + c_2x^2 $$
 * }
 * }

Solution

 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle P_2(x) = \sum_{i=0}^{2} l_i(x) f(x_i) $$
 * $$\displaystyle (Eq. 1) $$
 * }
 * }
 * }

We know from lecture slide Eq.2 [[media:Egm6341.s10.mtg7.pdf|p.7-3]],

Substitute i=0 and n=2 in Eq.(2),

Substitute i=1 and n=2 in Eq.(2),

Substitute i=2 and n=2 in Eq.(2),

Substituting Eq.(3) through Eq.(5) in Eq.(1),
 * {| style="width:100%" border="0" align="left"

$$\displaystyle = \Big[\frac{x^2 -xx_2-xx_1+x_1x_2} {(x_0 - x_1)(x_0 - x_2)}\Big] f(x_0) + \Big[\frac{x^2 -xx_0-xx_2+x_0x_2} {(x_1 - x_0)(x_1 - x_2)}\Big] f(x_1) + \Big[\frac{x^2 -xx_0-xx_1+x_0x_1} {(x_2 - x_0)(x_2 - x_1)}\Big] f(x_2) $$ $$\displaystyle Grouping\, the\, x, x^2\, and\, constant\, terms\, $$ $$\displaystyle P_2(x)\quad= \bigg[\frac{x_1x_2} {(x_0 - x_1)(x_0 - x_2)} f(x_0)  +  \frac{x_0x_2} {(x_1 - x_0)(x_1 - x_2)} f(x_1) +  \frac{x_0x_1} {(x_2 - x_0)(x_2 - x_1)} f(x_2)\bigg]  $$ $$\displaystyle - \bigg[ \frac{x_1+x_2} {(x_0 - x_1)(x_0 - x_2)} f(x_0)  +  \frac{x_0+x_2} {(x_1 - x_0)(x_1 - x_2)} f(x_1) +  \frac{x_0+x_1} {(x_2 - x_0)(x_2 - x_1)} f(x_2)\bigg] x $$ $$\displaystyle + \bigg[ \frac{1} {(x_0 - x_1)(x_0 - x_2)} f(x_0)  +  \frac{1} {(x_1 - x_0)(x_1 - x_2)} f(x_1) +  \frac{1} {(x_2 - x_0)(x_2 - x_1)} f(x_2)\bigg] x^2 $$
 * $$\displaystyle P_2(x) = l_0(x) f(x_0) + l_1(x) f(x_1) + l_2(x) f(x_2) $$
 * $$\displaystyle P_2(x) = l_0(x) f(x_0) + l_1(x) f(x_1) + l_2(x) f(x_2) $$
 * $$\displaystyle (Eq. 6) $$
 * }
 * }

Comparing Eq.(6) with
 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle f_2(x) = c_0 + c_1x + c_2x^2 $$
 * }
 * }
 * }

we find that,
 * {| style="width:100%" border="0" align="left"

$$\displaystyle c_0 = \frac{x_1x_2} {(x_0 - x_1)(x_0 - x_2)} f(x_0) +  \frac{x_0x_2} {(x_1 - x_0)(x_1 - x_2)} f(x_1) +  \frac{x_0x_1} {(x_2 - x_0)(x_2 - x_1)} f(x_2)  $$
 * style="width:25%; padding:10px; border:2px solid #8888aa" |
 * style="width:25%; padding:10px; border:2px solid #8888aa" |
 * style = |
 * }
 * }


 * {| style="width:100%" border="0" align="left"

$$\displaystyle c_1 = -\Bigg[ \frac{x_1+x_2} {(x_0 - x_1)(x_0 - x_2)} f(x_0) +  \frac{x_0+x_2} {(x_1 - x_0)(x_1 - x_2)} f(x_1) +  \frac{x_0+x_1} {(x_2 - x_0)(x_2 - x_1)} f(x_2)\Bigg]  $$
 * style="width:25%; padding:10px; border:2px solid #8888aa" |
 * style="width:25%; padding:10px; border:2px solid #8888aa" |
 * style = |
 * }
 * }


 * {| style="width:100%" border="0" align="left"

$$\displaystyle c_2 = \frac{1} {(x_0 - x_1)(x_0 - x_2)} f(x_0) +  \frac{1} {(x_1 - x_0)(x_1 - x_2)} f(x_1) +  \frac{1} {(x_2 - x_0)(x_2 - x_1)} f(x_2)  $$
 * style="width:25%; padding:10px; border:2px solid #8888aa" |
 * style="width:25%; padding:10px; border:2px solid #8888aa" |
 * style = |
 * }
 * }

= Derivation of the Simple Simpson's rule = Ref: Lecture Notes [[media:Egm6341.s10.mtg9.pdf|p.9-1]]

Problem Statement
Starting from $$\displaystyle p_2(x_j) = \sum_{i=0}^2 l_i(x_j) f(x_i)$$ derive the Simple Simpson's rule Use (4) in [[media:Egm6341.s10.mtg8.pdf|Lecture p.8-3]]to derive the Simple Simpson's rule (2) [[media:Egm6341.s10.mtg7.pdf|Lecture p.7-2]]

Solution
We use (4) in [[media:Egm6341.s10.mtg8.pdf|Lecture p.8-3]] to derive the left side of simple simpson's equation as follows:
 * {| style="width:100%" border="0" align="left"

I_2 & = \int_{a}^{b} P_2(x)\ dx \\ & = \int_{a}^{b} \sum_{i=0}^{2}l_i(x)f(x_i)\ dx \\ & = \int_{a}^{b} l_0(x)f(x_0) + l_1(x)f(x_1) + l_2(x)f(x_2)\ dx \\ & = f(x_0)\int_{a}^{b} l_0(x)\ dx + f(x_1)\int_{a}^{b} l_1(x)\ dx + f(x_2)\int_{a}^{b} l_2(x)\ dx \end{align} $$
 * $$ \displaystyle \begin{align}
 * $$ \displaystyle \begin{align}
 * $$\displaystyle (Eq. 1) $$
 * }
 * }

Where $$ x_0 = a, x_1 = \frac{a+b}{2}, x_2 = b $$

Next is to do the integration of $$ {l_0(x), l_1(x),  l_2(x)} $$


 * {| style="width:100%" border="0" align="left"

\int_{a}^{b} l_0(x)\ dx & = \int_{a}^{b}\frac{(x-x_1)(x-x_2)}{(x_0-x_1)(x_0-x_2)}\ dx \\ & = \int_{a}^{b}\frac{(x-\frac{a+b}{2})(x-b)}{(a-\frac{a+b}{2})(a-b)}\ dx \\ & = \frac{2}{(b-a)^2}\left [ \frac{x^3}{3} - \frac{a+3b}{4}x^2 + \frac{b(a+b)}{2}x \right ]_{a}^b \\ & = \frac{2}{(b-a)^2} \left [ \frac{(b-a)(b^2 + ab + a^2)}{3} - \frac{a+3b}{4}(b-a)(b+a) + \frac{b(a+b)}{2}(b-a) \right ] \\ & = \frac{2}{(b-a)} \left [ \frac{(b^2 + ab + a^2)}{3} - \frac{a+3b}{4}(b+a) + \frac{b(a+b)}{2} \right ] \\ & = \frac{(b-a)^2}{6(b-a)} \\ & = \frac{b-a}{6}\\ \end{align} $$
 * $$ \displaystyle \begin{align}
 * $$ \displaystyle \begin{align}
 * $$\displaystyle (Eq. 2) $$
 * }
 * }


 * {| style="width:100%" border="0" align="left"

\int_{a}^{b} l_1(x)\ dx & = \int_{a}^{b}\frac{(x-x_0)(x-x_2)}{(x_1-x_0)(x_1-x_2)}\ dx \\ & = \int_{a}^{b}\frac{(x-a)(x-b)}{(\frac{a+b}{2}-a)(\frac{a+b}{2}-b)}\ dx \\ & = \frac{4}{(b-a)(a-b)}\left [ \frac{x^3}{3} - \frac{a+b}{2}x^2 + abx \right ]_{a}^b \\ & = \frac{4}{(b-a)(a-b)}\left [ \frac{(b-a)(b^2+ab+a^2)}{3} - \frac{(a+b)(a+b)(a-b)}{2} + ab(b-a) \right ]_{a}^b \\ & = \frac{4}{(a-b)}\left [ \frac{(b^2+ab+a^2)}{3} - \frac{(a+b)(a+b)}{2} + ab \right ]_{a}^b \\ & = \frac{2(b-a)^2}{3(b-a)} \\ & = \frac{2(b-a)}{3}\\ \end{align} $$
 * $$ \displaystyle \begin{align}
 * $$ \displaystyle \begin{align}
 * $$\displaystyle (Eq. 3) $$
 * }
 * }


 * {| style="width:100%" border="0" align="left"

\int_{a}^{b} l_2(x) \ dx & = \int_{a}^{b}\frac{(x-x_0)(x-x_1)}{(x_2-x_0)(x_2-x_1)}\ dx \\ & = \int_{a}^{b}\frac{(x-a)(x-\frac{a+b}{2})}{(b-a)(b-\frac{a+b}{2})}\ dx \\ & = \frac{2}{(b-a)^2}\left [ \frac{x^3}{3} - \frac{3a+b}{4}x^2 + \frac{a(a+b)}{2}x \right ]_{a}^b \\ & = \frac{2}{(b-a)^2} \left [ \frac{(b-a)(b^2 + ab + a^2)}{3} - \frac{3a+b}{4}(b-a)(b+a) + \frac{b(a+b)}{2}(b-a) \right ] \\ & = \frac{2}{(b-a)} \left [ \frac{(b^2 + ab + a^2)}{3} - \frac{3a+b}{4}(b+a) + \frac{b(a+b)}{2} \right ] \\ & = \frac{(b-a)^2}{6(b-a)} \\ & = \frac{b-a}{6}\\ \end{align} $$
 * $$ \displaystyle \begin{align}
 * $$ \displaystyle \begin{align}
 * $$\displaystyle (Eq. 4) $$
 * }
 * }

Use Eq.1, Eq.2, Eq.3 and Eq.4, we have:


 * {| style="width:100%" border="0" align="left"

$$ \displaystyle \begin{align} \Rightarrow \ I_2 & = \frac{b-a}{6}f(x_0)+\frac{2(b-a)}{3}f(x_1)+\frac{b-a}{6}f(x_2)\\ & = \frac{b-a}{6}[f(x_0)+4f(x_1)+f(x_2)]\\ & = \frac{h}{3}[f(x_0)+4f(x_1)+f(x_2)] \end{align} $$ Where $$h = \frac{b-a}{2}$$
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style = |
 * }

= Newton-Cotes Method - Constructing $$f_n(x)$$ for varying n = Ref: Lecture notes [[media:Egm6341.s10.mtg9.pdf|p.9-2]]

Problem Statement
Consider $$ f(x)=\frac{e^{x}-1}{x} $$ on $$ x\in[0,1], \quad x_{0}=a=0, \quad x_{n}=b=1 $$.

(i) Construct $$ f_{n}(x)= \sum_{i=0}^{n}l_{i,n}(x)f(x_{i}) $$ for n = 1, 2, 4, 8, 16.

(ii) Plot $$\displaystyle f(x) $$ and $$\displaystyle f_{n}(x) $$ for n = 1, 2, 4, 8, 16.

(iii) Compute $$ I_{n}=\int_{b}^{b}f_{n}(x)dx $$ for n = 1, 2, 4, 8 and compare to $$\displaystyle I $$.

(iv) For n = 4, plot $$\displaystyle l_{0}, l_{1}, l_{2} $$.

(v) Why don't we have to take a look at $$\displaystyle l_{3}, l_{4} $$ for n = 4?

Solution
Recall the formula
 * {| style="width:100%" border="0" align="left"

l_{i,n}(x) = \prod_{j=0,i\neq j}^{n}\frac{x-x_{j}}{x_{i}-x_{j}} $$ from [[media:Egm6341.s10.mtg7.pdf|p.7-3]] of lecture note.
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (Eq. 1) $$
 * }
 * }

(i)

When n = 1 $$\displaystyle \rightarrow x_{0} = 0, x_{1} = 1 $$.


 * {| style="width:100%" border="0" align="left"

f_{1}=\sum_{i=0}^{1}l_{i,1}(x)f(x_{i})=l_{0,1}(x)f(x_{0})+l_{1,1}(x)f(x_{1}) $$ where
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (Eq. 2) $$
 * }
 * }
 * {| style="width:100%" border="0" align="left"

l_{0,1}=\prod_{j=0,j\neq 0}^{1}\frac{x-x_{j}}{x_{0}-x_{j}}=\frac{x-1}{0-1}, \quad f(x_{0})=f(0)=1, $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{1,1}=\prod_{j=0,j\neq 1}^{1}\frac{x-x_{j}}{x_{1}-x_{j}}=\frac{x-0}{1-0}, \quad f(x_{1})=f(1)=e-1. $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * }

When n = 2 $$ \rightarrow x_{0} = 0, x_{1} = \frac{1}{2}, x_{2} = 1 $$.


 * {| style="width:100%" border="0" align="left"

f_{2}=\sum_{i=0}^{2}l_{i,2}(x)f(x_{i})=l_{0,2}(x)f(x_{0})+l_{1,2}(x)f(x_{1})+l_{2,2}(x)f(x_{2}) $$ where
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (Eq. 4) $$
 * }
 * }
 * {| style="width:100%" border="0" align="left"

l_{0,2}=\prod_{j=0,j\neq 0}^{2}\frac{x-x_{j}}{x_{0}-x_{j}}=\frac{(x-\frac{1}{2})(x-1)}{(0-\frac{1}{2}(0-1)}, \quad f(x_{0})=f(0)=1, $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{1,2}=\prod_{j=0,j\neq 1}^{2}\frac{x-x_{j}}{x_{1}-x_{j}}=\frac{(x-0)(x-1)}{(\frac{1}{2}-0)(\frac{1}{2}-1)}, \quad f(x_{1})=f(\frac{1}{2})=2\left(e^{\frac{1}{2}}-1\right), $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{2,2}=\prod_{j=0,j\neq 2}^{2}\frac{x-x_{j}}{x_{2}-x_{j}}=\frac{(x-0)(x-\frac{1}{2})}{(1-0)(1-\frac{1}{2})}, \quad f(x_{2})=f(1)=e-1. $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * }

When n = 4 $$ \rightarrow x_{0} = 0, x_{1} = \frac{1}{4}, x_{2} = \frac{2}{4}, x_{3} = \frac{3}{4}, x_{4} = 1 $$.


 * {| style="width:100%" border="0" align="left"

f_{4}=\sum_{i=0}^{4}l_{i,4}(x)f(x_{i})=l_{0,4}(x)f(x_{0})+l_{1,4}(x)f(x_{1})+l_{2,4}(x)f(x_{2})+l_{3,4}(x)f(x_{3})+l_{4,4}(x)f(x_{4}) $$ where
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (Eq. 5) $$
 * }
 * }
 * {| style="width:100%" border="0" align="left"

l_{0,4}=\prod_{j=0,j\neq 0}^{4}\frac{x-x_{j}}{x_{0}-x_{j}}=\frac{(x-\frac{1}{4})(x-\frac{2}{4})(x-\frac{3}{4})(x-1)}{(0-\frac{1}{4})(0-\frac{2}{4})(0-\frac{3}{4})(0-1)}, \quad f(x_{0})=f(0)=1, $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{1,4}=\prod_{j=0,j\neq 1}^{4}\frac{x-x_{j}}{x_{1}-x_{j}}=\frac{(x-0)(x-\frac{2}{4})(x-\frac{3}{4})(x-1)}{(\frac{1}{4}-0)(\frac{1}{4}-\frac{2}{4})(\frac{1}{4}-\frac{3}{4})(\frac{1}{4}-1)}, \quad f(x_{1})=f(\frac{1}{4})=4\left(e^{\frac{1}{4}}-1\right), $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{2,4}=\prod_{j=0,j\neq 2}^{4}\frac{x-x_{j}}{x_{2}-x_{j}}=\frac{(x-0)(x-\frac{1}{4})(x-\frac{3}{4})(x-1)}{(\frac{2}{4}-0)(\frac{2}{4}-\frac{1}{4})(\frac{2}{4}-\frac{3}{4})(\frac{2}{4}-1)}, \quad f(x_{2})=f(\frac{2}{4})=2\left(e^{\frac{2}{4}}-1\right), $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{3,4}=\prod_{j=0,j\neq 3}^{4}\frac{x-x_{j}}{x_{3}-x_{j}}=\frac{(x-0)(x-\frac{1}{4})(x-\frac{2}{4})(x-1)}{(\frac{3}{4}-0)(\frac{3}{4}-\frac{1}{4})(\frac{3}{4}-\frac{2}{4})(\frac{3}{4}-1)}, \quad f(x_{3})=f(\frac{3}{4})=\frac{4}{3}\left(e^{\frac{3}{4}}-1\right), $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{4,4}=\prod_{j=0,j\neq 4}^{4}\frac{x-x_{j}}{x_{4}-x_{j}}=\frac{(x-0)(x-\frac{1}{4})(x-\frac{2}{4})(x-\frac{3}{4})}{(1-0)(1-\frac{1}{4})(1-\frac{2}{4})(1-\frac{3}{4})}, \quad f(x_{4})=f(1)=e-1, $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * }

When n = 8 $$ \rightarrow x_{0} = 0, x_{1} = \frac{1}{8}, x_{2} = \frac{2}{8}, x_{3} = \frac{3}{8}, x_{4} = \frac{4}{8}, x_{5} = \frac{5}{8}, x_{6} = \frac{6}{8}, x_{7} = \frac{7}{8}, x_{8} = 1 $$.


 * {| style="width:100%" border="0" align="left"

f_{8}=\sum_{i=0}^{8}l_{i,8}(x)f(x_{i})=l_{0,8}(x)f(x_{0})+l_{1,8}(x)f(x_{1})+l_{2,8}(x)f(x_{2})+l_{3,8}(x)f(x_{3})+l_{4,8}(x)f(x_{4})+l_{5,8}(x)f(x_{5})+l_{6,8}(x)f(x_{6})+l_{7,8}(x)f(x_{7})+l_{8,8}(x)f(x_{8}) $$ where
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (Eq. 6) $$
 * }
 * }
 * {| style="width:100%" border="0" align="left"

l_{0,8}=\prod_{j=0,j\neq 0}^{8}\frac{x-x_{j}}{x_{0}-x_{j}}=\frac{(x-\frac{1}{8})(x-\frac{2}{8})(x-\frac{3}{8})(x-\frac{4}{8})(x-\frac{5}{8})(x-\frac{6}{8})(x-\frac{7}{8})(x-1)}{(0-\frac{1}{8})(0-\frac{2}{8})(0-\frac{3}{8})(0-\frac{4}{8})(0-\frac{5}{8})(0-\frac{6}{8})(0-\frac{7}{8})(0-1)}, \quad f(x_{0})=f(0)=1, $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{1,8}=\prod_{j=0,j\neq 1}^{8}\frac{x-x_{j}}{x_{1}-x_{j}}=\frac{(x-0)(x-\frac{2}{8})(x-\frac{3}{8})(x-\frac{4}{8})(x-\frac{5}{8})(x-\frac{6}{8})(x-\frac{7}{8})(x-1)}{(\frac{1}{8}-0)(\frac{1}{8}-\frac{2}{8})(\frac{1}{8}-\frac{3}{8})(\frac{1}{8}-\frac{4}{8})(\frac{1}{8}-\frac{5}{8})(\frac{1}{8}-\frac{6}{8})(\frac{1}{8}-\frac{7}{8})(\frac{1}{8}-1)}, \quad f(x_{1})=f(\frac{1}{8})=8\left(e^{\frac{1}{8}}-1\right), $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{2,8}=\prod_{j=0,j\neq 2}^{8}\frac{x-x_{j}}{x_{2}-x_{j}}=\frac{(x-0)(x-\frac{1}{8})(x-\frac{3}{8})(x-\frac{4}{8})(x-\frac{5}{8})(x-\frac{6}{8})(x-\frac{7}{8})(x-1)}{(\frac{2}{8}-0)(\frac{2}{8}-\frac{1}{8})(\frac{2}{8}-\frac{3}{8})(\frac{2}{8}-\frac{4}{8})(\frac{2}{8}-\frac{5}{8})(\frac{2}{8}-\frac{6}{8})(\frac{2}{8}-\frac{7}{8})(\frac{2}{8}-1)}, \quad f(x_{2})=f(\frac{2}{8})=\frac{8}{2}\left(e^{\frac{2}{8}}-1\right), $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{3,8}=\prod_{j=0,j\neq 3}^{8}\frac{x-x_{j}}{x_{3}-x_{j}}=\frac{(x-0)(x-\frac{1}{8})(x-\frac{2}{8})(x-\frac{4}{8})(x-\frac{5}{8})(x-\frac{6}{8})(x-\frac{7}{8})(x-1)}{(\frac{3}{8}-0)(\frac{3}{8}-\frac{1}{8})(\frac{3}{8}-\frac{2}{8})(\frac{3}{8}-\frac{4}{8})(\frac{3}{8}-\frac{5}{8})(\frac{3}{8}-\frac{6}{8})(\frac{3}{8}-\frac{7}{8})(\frac{3}{8}-1)}, \quad f(x_{3})=f(\frac{3}{8})=\frac{8}{3}\left(e^{\frac{3}{8}}-1\right), $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{4,8}=\prod_{j=0,j\neq 4}^{8}\frac{x-x_{j}}{x_{4}-x_{j}}=\frac{(x-0)(x-\frac{1}{8})(x-\frac{2}{8})(x-\frac{3}{8})(x-\frac{5}{8})(x-\frac{6}{8})(x-\frac{7}{8})(x-1)}{(\frac{4}{8}-0)(\frac{4}{8}-\frac{1}{8})(\frac{4}{8}-\frac{2}{8})(\frac{4}{8}-\frac{3}{8})(\frac{4}{8}-\frac{5}{8})(\frac{4}{8}-\frac{6}{8})(\frac{4}{8}-\frac{7}{8})(\frac{4}{8}-1)}, \quad f(x_{4})=f(\frac{4}{8})=\frac{8}{4}\left(e^{\frac{4}{8}}-1\right), $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{5,8}=\prod_{j=0,j\neq 5}^{8}\frac{x-x_{j}}{x_{5}-x_{j}}=\frac{(x-0)(x-\frac{1}{8})(x-\frac{2}{8})(x-\frac{3}{8})(x-\frac{4}{8})(x-\frac{6}{8})(x-\frac{7}{8})(x-1)}{(\frac{5}{8}-0)(\frac{5}{8}-\frac{1}{8})(\frac{5}{8}-\frac{2}{8})(\frac{5}{8}-\frac{3}{8})(\frac{5}{8}-\frac{4}{8})(\frac{5}{8}-\frac{6}{8})(\frac{5}{8}-\frac{7}{8})(\frac{5}{8}-1)}, \quad f(x_{5})=f(\frac{5}{8})=\frac{8}{5}\left(e^{\frac{5}{8}}-1\right), $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{6,8}=\prod_{j=0,j\neq 6}^{8}\frac{x-x_{j}}{x_{6}-x_{j}}=\frac{(x-0)(x-\frac{1}{8})(x-\frac{2}{8})(x-\frac{3}{8})(x-\frac{4}{8})(x-\frac{5}{8})(x-\frac{7}{8})(x-1)}{(\frac{6}{8}-0)(\frac{6}{8}-\frac{1}{8})(\frac{6}{8}-\frac{2}{8})(\frac{6}{8}-\frac{3}{8})(\frac{6}{8}-\frac{4}{8})(\frac{6}{8}-\frac{5}{8})(\frac{6}{8}-\frac{7}{8})(\frac{6}{8}-1)}, \quad f(x_{6})=f(\frac{6}{8})=\frac{8}{6}\left(e^{\frac{6}{8}}-1\right), $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{7,8}=\prod_{j=0,j\neq 7}^{8}\frac{x-x_{j}}{x_{7}-x_{j}}=\frac{(x-0)(x-\frac{1}{8})(x-\frac{2}{8})(x-\frac{3}{8})(x-\frac{4}{8})(x-\frac{5}{8})(x-\frac{6}{8})(x-1)}{(\frac{7}{8}-0)(\frac{7}{8}-\frac{1}{8})(\frac{7}{8}-\frac{2}{8})(\frac{7}{8}-\frac{3}{8})(\frac{7}{8}-\frac{4}{8})(\frac{7}{8}-\frac{5}{8})(\frac{7}{8}-\frac{6}{8})(\frac{7}{8}-1)}, \quad f(x_{7})=f(\frac{7}{8})=\frac{8}{7}\left(e^{\frac{7}{8}}-1\right), $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{8,8}=\prod_{j=0,j\neq 8}^{8}\frac{x-x_{j}}{x_{8}-x_{j}}=\frac{(x-0)(x-\frac{1}{8})(x-\frac{2}{8})(x-\frac{3}{8})(x-\frac{4}{8})(x-\frac{5}{8})(x-\frac{6}{8})(x-\frac{7}{8})}{(1-0)(1-\frac{1}{8})(1-\frac{2}{8})(1-\frac{3}{8})(1-\frac{4}{8})(1-\frac{5}{8})(1-\frac{6}{8})(1-\frac{7}{8})}, \quad f(x_{8})=f(1)=e-1. $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * }

When n = 16 $$ \rightarrow x_{0} = 0, x_{1} = \frac{1}{16}, x_{2} = \frac{2}{16}, x_{3} = \frac{3}{16}, x_{4} = \frac{4}{16}, x_{5} = \frac{5}{16}, x_{6} = \frac{6}{16}, x_{7} = \frac{7}{16}, x_{8} = \frac{8}{16}, x_{9} = \frac{9}{16}, x_{10} = \frac{10}{16}, x_{11} = \frac{11}{16}, x_{12} = \frac{12}{16}, x_{13} = \frac{13}{16}, x_{14} = \frac{14}{16}, x_{15} = \frac{15}{16}, x_{16} = 1 $$.


 * {| style="width:100%" border="0" align="left"

f_{16}=\sum_{i=0}^{16}l_{i,16}(x)f(x_{i})=l_{0,16}(x)f(x_{0})+l_{1,16}(x)f(x_{1})+l_{2,16}(x)f(x_{2})+l_{3,16}(x)f(x_{3})+l_{4,16}(x)f(x_{4})+l_{5,16}(x)f(x_{5})+l_{6,16}(x)f(x_{6})+l_{7,16}(x)f(x_{7})+l_{8,16}(x)f(x_{8})+l_{9,16}(x)f(x_{9})+l_{10,16}(x)f(x_{10})+l_{11,16}(x)f(x_{11})+l_{12,16}(x)f(x_{12})+l_{13,16}(x)f(x_{13})+l_{14,16}(x)f(x_{14})+l_{15,16}(x)f(x_{15})+l_{16,16}(x)f(x_{16}) $$ where
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (Eq. 7) $$
 * }
 * }
 * {| style="width:100%" border="0" align="left"

l_{0,16}=\prod_{j=0,j\neq 0}^{16}\frac{x-x_{j}}{x_{0}-x_{j}}=\frac{(x-\frac{1}{16})(x-\frac{2}{16})(x-\frac{3}{16})(x-\frac{4}{16})(x-\frac{5}{16})(x-\frac{6}{16})(x-\frac{7}{16})(x-\frac{8}{16})(x-\frac{9}{16})(x-\frac{10}{16})(x-\frac{11}{16})(x-\frac{12}{16})(x-\frac{13}{16})(x-\frac{14}{16})(x-\frac{15}{16})(x-1)}{(0-\frac{1}{16})(0-\frac{2}{16})(0-\frac{3}{16})(0-\frac{4}{16})(0-\frac{5}{16})(0-\frac{6}{16})(0-\frac{7}{16})(0-\frac{8}{16})(0-\frac{9}{16})(0-\frac{10}{16})(0-\frac{11}{16})(0-\frac{12}{16})(0-\frac{13}{16})(0-\frac{14}{16})(0-\frac{15}{16})(0-1)}, \quad f(x_{0})=f(0)=1, $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{1,16}=\prod_{j=0,j\neq 1}^{16}\frac{x-x_{j}}{x_{1}-x_{j}}=\frac{(x-0)(x-\frac{2}{16})(x-\frac{3}{16})(x-\frac{4}{16})(x-\frac{5}{16})(x-\frac{6}{16})(x-\frac{7}{16})(x-\frac{8}{16})(x-\frac{9}{16})(x-\frac{10}{16})(x-\frac{11}{16})(x-\frac{12}{16})(x-\frac{13}{16})(x-\frac{14}{16})(x-\frac{15}{16})(x-1)}{(\frac{1}{16}-0)(\frac{1}{16}-\frac{2}{16})(\frac{1}{16}-\frac{3}{16})(\frac{1}{16}-\frac{4}{16})(\frac{1}{16}-\frac{5}{16})(\frac{1}{16}-\frac{6}{16})(\frac{1}{16}-\frac{7}{16})(\frac{1}{16}-\frac{8}{16})(\frac{1}{16}-\frac{9}{16})(\frac{1}{16}-\frac{10}{16})(\frac{1}{16}-\frac{11}{16})(\frac{1}{16}-\frac{12}{16})(\frac{1}{16}-\frac{13}{16})(\frac{1}{16}-\frac{14}{16})(\frac{1}{16}-\frac{15}{16})(\frac{1}{16}-1)}, \quad f(x_{1})=f(\frac{1}{16})=16\left(e^{\frac{1}{16}}-1\right), $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * }

$$\cdot$$ $$\cdot$$ $$\cdot$$ $$\cdot$$ $$\cdot$$ $$\cdot$$


 * {| style="width:100%" border="0" align="left"

l_{16,16}=\prod_{j=0,j\neq 16}^{16}\frac{x-x_{j}}{x_{16}-x_{j}}=\frac{(x-0)(x-\frac{1}{16})(x-\frac{2}{16})(x-\frac{3}{16})(x-\frac{4}{16})(x-\frac{5}{16})(x-\frac{6}{16})(x-\frac{7}{16})(x-\frac{8}{16})(x-\frac{9}{16})(x-\frac{10}{16})(x-\frac{11}{16})(x-\frac{12}{16})(x-\frac{13}{16})(x-\frac{14}{16})(x-\frac{15}{16})}{(1-0)(1-\frac{1}{16})(1-\frac{2}{16})(1-\frac{3}{16})(1-\frac{4}{16})(1-\frac{5}{16})(1-\frac{6}{16})(1-\frac{7}{16})(1-\frac{8}{16})(1-\frac{9}{16})(1-\frac{10}{16})(1-\frac{11}{16})(1-\frac{12}{16})(1-\frac{13}{16})(1-\frac{14}{16})(1-\frac{15}{16})}, \quad f(x_{16})=f(1)=e-1, $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * }

(ii)

 Matlab code of this plots is provided in the end of this document 

In order to compare the plots of different functions, it is definitely efficient to plot all functions in the same figure. In this case, however, the plots of functions $$\displaystyle f_{n}(x) $$ for n = 2, 4, 8, 16 almost overlap with $$\displaystyle f(x) $$ for $$\displaystyle x \in [0, 1] $$, and thus we cannot distinguish a specific plot from the others. Thus, we use separate figures for each plot of functions.

Plot $$\displaystyle f(x) = \frac{e^{x}-1}{x} $$

Plot $$\displaystyle f_{1}(x)$$

Plot $$\displaystyle f_{2}(x)$$

Plot $$\displaystyle f_{4}(x)$$

Plot $$\displaystyle f_{8}(x)$$

Plot $$\displaystyle f_{16}(x)$$

(iii)

 Matlab code of this calculations is provided in the end of this document 

(iv)

 Matlab code of this plots is provided in the end of this document 

Plots of $$\displaystyle l_{0}, l_{1}, l_{2} $$ when n = 4.

(v)

 Matlab code of this plots is provided in the end of this document 

As the plots of $$\displaystyle l_{i} $$ for all $$\displaystyle i $$ in the figure below, the plots of $$\displaystyle l_{3} $$ and $$\displaystyle l_{4} $$ are the mirror images of $$\displaystyle l_{1} $$ and $$\displaystyle l_{0} $$ respectively with respect to $$\displaystyle x = x_{2}=0.5 $$. Therefore, we don't need to take a look at the plots of $$\displaystyle l_{3} $$ and $$\displaystyle l_{4} $$ if we already get the plots of $$\displaystyle l_{0} $$ and $$\displaystyle l_{1} $$.

Matlab code for (ii), (iii), (iv) and (v)

For this problem, one global code is much more efficient than the several short codes for each parts of problem. Therefore, we are providing a comprehensive code below.

= Derivation:Composite trapezoidal rule and Composite simpson's rule from simple trapezoidal and simple simpson's rule =

Ref Lecture notes [[media:Egm6341.s10.mtg9.pdf|p.9-3]]

Problem Statement
Derive composite Trapezoidal rule[[media:Egm6341.s10.mtg7.pdf|p.7-1]] from Simple Trapezoidal rule [[media:Egm6341.s10.mtg7.pdf|p.7-1]]

and

Derive composite Simpson's rule [[media:Egm6341.s10.mtg7.pdf|p.7-2]] from simple Simpson's rule[[media:Egm6341.s10.mtg7.pdf|p.7-2]]

Solution
Composite Trapezoidal rule

From Simple trapezoidal rule we have ,

$$ I_1 = \frac{h}{2}[f_{\text{o}}+ f_1] $$

$$    = h [\frac{1}{2}f_{\text{o}}+\frac{1}{2} f_1]     $$

similarly we have

$$ I_2 = h [\frac{1}{2}f_1+\frac{1}{2} f_2] $$

$$ I_3 = h [\frac{1}{2}f_2+\frac{1}{2} f_3] $$ . . . . $$ I_{\text{n-1}} = h [\frac{1}{2}f_{\text{n-2}}+\frac{1}{2} f_{\text{n-1}}] $$

$$ I_{\text{n}} = h [\frac{1}{2}f_{\text{n-1}}+\frac{1}{2} f_{\text{n}}] $$

Summation of all of above expression gives

$$ I_{\text{n}} = h [\frac{1}{2}f_{\text{o}}+(\frac{1}{2} f_1 +\frac{1}{2} f_1)+(\frac{1}{2} f_2+\frac{1}{2} f_2)+.....+(\frac{1}{2} f_{\text{n-1}}+\frac{1}{2} f_{\text{n-1}})+ \frac{1}{2} f_{\text{n}} ] $$

$$ = h [\frac{1}{2}f_{\text{o}}+ f_1 + f_2 +.......+ f_{\text{n-1}} +\frac{1}{2} f_{\text{n}}]$$

Hence Proved..

Composite Simpson's Rule

From Simple Simpson's rule we obtain ,

$$ I_2 = \frac {h}{3} [f_{\text{o}}+4 f_1 +f_2] $$

where $$ h = \frac {b-a}{2}$$

Similarly

$$ I_4 = \frac {h}{3} [f_2+4 f_3 +f_4] $$

$$ I_6 = \frac {h}{3} [f_4+4 f_5 +f_6] $$ . . . . $$ I_{\text{n-2}} = \frac {h}{3} [f_{\text{n-4}}+4 f_{\text{n-3}} +f_{\text{n-2}}] $$

$$ I_{\text{n}} = \frac {h}{3} [f_{\text{n-2}}+4 f_{\text{n-1}} +f_{\text{n}}] $$

After Summation of above terms we obtain

$$ I_{\text{n}} = \frac {h}{3} [f_{\text{o}}+4 f_1+(f_2+f_2)+4f_{\text{3}}+(f_4+f_4)+4f_5+f_6.......+(f_{\text{n-2}}+f_{\text{n-2}})+4 f_{\text{n-1}} +f_{\text{n}}] $$

$$ I_{\text{n}} = \frac {h}{3} [f_{\text{o}}+4 f_1+2f_2+4f_{\text{3}}+2f_4+4f_5+f_6.......+2f_{\text{n-2}}+4 f_{\text{n-1}} +f_{\text{n}}] $$

where n = 2k  and k = 1,2,3,4.....

Hence Proved

Find n such that error in Taylor series is less than the error from Lagrange series
Ref: Lecture Notes [[media:Egm6341.s10.mtg11.pdf|p.11-1]]

Problem Statement
Find n at $$ \displaystyle \left|{f}_{n}^{T}(\frac{7\pi}{8}) - f(\frac{7\pi}{8})\right| \leq \left|{f}_{4}^{L}(\frac{7\pi}{8}) - f(\frac{7\pi}{8})\right| \leq \left| \frac{{q}_{5}(t)}{5!} \right| $$  for  $$ \displaystyle f(x) = sin(x) $$ and $$ \displaystyle x_{0} = 0, x_{1} = \frac{\pi}{4}, x_{2} = \frac{\pi}{2}, x_{3} = \frac{3\pi}{4}, x_{4} = 1 $$.

Solution
Matlab codes for this problem is provided later.

First, construct Lagrange interpolating function $$ f_{4}^{L}(x) $$ and polynomial $$\displaystyle q_{5}(x) $$.


 * {| style="width:100%" border="0" align="left"

f_{4}^{L}(x)=P_{4}(x)= \sum_{i=0}^{4}l_{i,4}(x)f(x_{i}) $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (Eq. 1) $$
 * }
 * }

where


 * {| style="width:100%" border="0" align="left"

l_{i,4}(x)=\Pi_{j=0, j \neq 4}^{4}\frac{x-x_{j}}{x_{i}-x_{j}} $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (Eq. 2) $$
 * }
 * }

Then, compare the constructed function $$\displaystyle f_{4}^{L}(x)$$ with the original function $$\displaystyle f(x)=sin(x)$$ by plotting them in the same figure.

Now, to check the fact $$\displaystyle \left|{f}_{4}^{L}(\frac{7\pi}{8}) - f(\frac{7\pi}{8})\right| \leq \left| \frac{{q}_{5}(t)}{5!} \right| $$, compute $$\displaystyle f_{4}^{L}(\frac{7\pi}{8})$$, $$\displaystyle f(\frac{7\pi}{8})$$ and $$\displaystyle \frac{\left|q_{5}(\frac{7\pi}{8})\right|}{5!}$$.


 * {| style="width:100%" border="0" align="left"

f_{4}^{L}(\frac{7\pi}{8}) = 3.812026433338313e-001 $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

f(\frac{7\pi}{8}) = sin(\frac{7\pi}{8}) = 3.826834260893118e-001 $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

\frac{\left|q_{5}(\frac{7\pi}{8})\right|}{5!} = 8.171616062246945e-003 $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * }

Therefore,
 * {| style="width:100%" border="0" align="left"

\left|E_{4}^{L}(\frac{7\pi}{8})\right|=\left|{f}_{4}^{L}(\frac{7\pi}{8}) - f(\frac{7\pi}{8})\right| \leq \left| \frac{{q}_{5}(t)}{5!} \right| $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * }


 * {| style="width:100%" border="0" align="left"

$$\displaystyle \Rightarrow \left|E_{4}^{L}(\frac{7\pi}{8})\right| = 1.480782755480525e-003 \leq \frac{\left|q_{5}(\frac{7\pi}{8})\right|}{5!} = 8.171616062246945e-003 $$
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style = |
 * }
 * }

 Matlab code for above plot and calculations 

Now, calculate $$ \displaystyle \left|{f}_{n}^{T}(\frac{7\pi}{8}) - f(\frac{7\pi}{8})\right| \leq 1.480782755480525e-003 $$ when $$ \displaystyle n=0, 1, 2, 3... n $$

Taylor Expansion of $$ \displaystyle f(x)=sin(x) $$ at $$ \displaystyle x_0 = \frac{\pi}{4} $$ Ref: Homework No. 1 [|Question 7]

a) Case 1 ($$\displaystyle n=0 $$) $$ \left|{f}_{0}^{T}(x) - f(x)\right| = \left| sin(x) - sin(x)\right| = 0 $$

b) Case 2 ($$\displaystyle n=1 $$) $$ \left|{f}_{0}^{T}(x) + {f}_{1}^{T}(x) - f(x)\right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(x-\frac{\pi}{4})}{1!}\Bigg] - sin(x) \right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})}{1!}\Bigg] -sin(\frac{7\pi}{8}) \right| = 1.712824266995947 $$

c) Case 3 ($$\displaystyle n=2 $$) $$ \left|{f}_{0}^{T}(x) + {f}_{1}^{T}(x) + {f}_{2}^{T}(x) - f(x)\right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(x-\frac{\pi}{4})}{1!} - \frac{(x-\frac{\pi}{4})^2}{2!} \Bigg] - sin(x) \right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})}{1!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^2}{2!} \Bigg] -sin(\frac{7\pi}{8}) \right| = 0.349764853003978 $$

d) Case 4 ($$\displaystyle n=3 $$) $$ \left|{f}_{0}^{T}(x) + {f}_{1}^{T}(x) + {f}_{2}^{T}(x) + {f}_{3}^{T}(x) - f(x)\right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(x-\frac{\pi}{4})}{1!} - \frac{(x-\frac{\pi}{4})^2}{2!} - \frac{(x-\frac{\pi}{4})^3}{3!} \Bigg] - sin(x) \right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})}{1!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^2}{2!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^3}{3!} \Bigg] -sin(\frac{7\pi}{8}) \right| = 0.542355447288433 $$

e) Case 5 ($$\displaystyle n=4 $$) $$ \left|{f}_{0}^{T}(x) + {f}_{1}^{T}(x) + {f}_{2}^{T}(x) + {f}_{3}^{T}(x) + {f}_{4}^{T}(x)- f(x)\right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(x-\frac{\pi}{4})}{1!} - \frac{(x-\frac{\pi}{4})^2}{2!} - \frac{(x-\frac{\pi}{4})^3}{3!} + \frac{(x-\frac{\pi}{4})^4}{4!} \Bigg] - sin(x) \right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})}{1!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^2}{2!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^3}{3!} + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^4}{4!} \Bigg] -sin(\frac{7\pi}{8}) \right| = 0.104436918926408 $$

f) Case 6 ($$\displaystyle n=5 $$) $$ \left|{f}_{0}^{T}(x) + {f}_{1}^{T}(x) + {f}_{2}^{T}(x) + {f}_{3}^{T}(x) + {f}_{4}^{T}(x)+ {f}_{5}^{T}(x) - f(x)\right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(x-\frac{\pi}{4})}{1!} - \frac{(x-\frac{\pi}{4})^2}{2!} - \frac{(x-\frac{\pi}{4})^3}{3!} + \frac{(x-\frac{\pi}{4})^4}{4!} + \frac{(x-\frac{\pi}{4})^5}{5!} \Bigg] - sin(x) \right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})}{1!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^2}{2!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^3}{3!} + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^4}{4!} + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^5}{5!} \Bigg] -sin(\frac{7\pi}{8}) \right| = 0.067533285020216 $$

g) Case 7 ($$\displaystyle n=6 $$) $$ \left|{f}_{0}^{T}(x) + {f}_{1}^{T}(x) + {f}_{2}^{T}(x) + {f}_{3}^{T}(x) + {f}_{4}^{T}(x) + {f}_{5}^{T}(x) + {f}_{6}^{T}(x) - f(x)\right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(x-\frac{\pi}{4})}{1!} - \frac{(x-\frac{\pi}{4})^2}{2!} - \frac{(x-\frac{\pi}{4})^3}{3!} + \frac{(x-\frac{\pi}{4})^4}{4!} + \frac{(x-\frac{\pi}{4})^5}{5!} - \frac{(x-\frac{\pi}{4})^6}{6!} \Bigg] - sin(x) \right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})}{1!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^2}{2!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^3}{3!} + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^4}{4!} + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^5}{5!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^6}{6!} \Bigg] -sin(\frac{7\pi}{8}) \right| = 0.011256167379064 $$

h) Case 8 ($$\displaystyle n=7 $$) $$ \left|{f}_{0}^{T}(x) + {f}_{1}^{T}(x) + {f}_{2}^{T}(x) + {f}_{3}^{T}(x) + {f}_{4}^{T}(x) + {f}_{5}^{T}(x) + {f}_{6}^{T}(x) + {f}_{7}^{T}(x) - f(x)\right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(x-\frac{\pi}{4})}{1!} - \frac{(x-\frac{\pi}{4})^2}{2!} - \frac{(x-\frac{\pi}{4})^3}{3!} + \frac{(x-\frac{\pi}{4})^4}{4!} + \frac{(x-\frac{\pi}{4})^5}{5!} - \frac{(x-\frac{\pi}{4})^6}{6!} - \frac{(x-\frac{\pi}{4})^7}{7!} \Bigg] - sin(x) \right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})}{1!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^2}{2!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^3}{3!} + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^4}{4!} + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^5}{5!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^6}{6!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^7}{7!} \Bigg] -sin(\frac{7\pi}{8}) \right| = 0.004529527205458 $$

i) Case 9 ($$\displaystyle n=8 $$) $$ \left|{f}_{0}^{T}(x) + {f}_{1}^{T}(x) + {f}_{2}^{T}(x) + {f}_{3}^{T}(x) + {f}_{4}^{T}(x) + {f}_{5}^{T}(x) + {f}_{6}^{T}(x) + {f}_{7}^{T}(x) + {f}_{8}^{T}(x) - f(x)\right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(x-\frac{\pi}{4})}{1!} - \frac{(x-\frac{\pi}{4})^2}{2!} - \frac{(x-\frac{\pi}{4})^3}{3!} + \frac{(x-\frac{\pi}{4})^4}{4!} + \frac{(x-\frac{\pi}{4})^5}{5!} - \frac{(x-\frac{\pi}{4})^6}{6!} - \frac{(x-\frac{\pi}{4})^7}{7!} + \frac{(x-\frac{\pi}{4})^8}{8!} \Bigg] - sin(x) \right| $$ $$ = \left| \frac{1}{\sqrt{2}}\Bigg[1 + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})}{1!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^2}{2!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^3}{3!} + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^4}{4!} + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^5}{5!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^6}{6!} - \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^7}{7!} + \frac{(\frac{7\pi}{8}-\frac{\pi}{4})^8}{8!} \Bigg] -sin(\frac{7\pi}{8}) \right| = 6.551348508838095*10^{-4} $$

Compare with the value of $$ \left|{f}_{4}^{L}(\frac{7\pi}{8}) - f(\frac{7\pi}{8})\right| $$

Thus, $$ \left|{f}_{n}^{T}(\frac{7\pi}{8}) - f(\frac{7\pi}{8})\right| $$ is smaller than $$ \left|{f}_{4}^{L}(\frac{7\pi}{8}) - f(\frac{7\pi}{8})\right| $$ when n=8.

--Heejun Chung 23:49, 20 February 2010 (UTC)

=Lagrange Interpolation Error - $$(n+1)^{th} $$ derivative= Ref: Lecture Notes [[media:Egm6341.s10.mtg12.pdf|p.12-2]]

Problem Statement
Prove that
 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle E^{n+1}(x) = f^{n+1}(x) $$
 * }
 * }
 * }

Solution
From lecture slide [[media:Egm6341.s10.mtg10.pdf|p.10-2]], we know that the Lagrange interpolation error is given by,
 * {| style="width:100%" border="0" align="left"

where,
 * $$\displaystyle E(x) := f(x) - f_n(x) $$
 * $$\displaystyle (Eq. 1) $$
 * }
 * }
 * }
 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle E(x) \; $$Interpolation error
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle f(x) \; $$ Actual function
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle f_n(x) \; $$ Inerpolating polynomial of order n
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"


 * Now differentiating Eq (1) n+1 times,
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle E^{n+1}(x)= f^{n+1}(x) + \cancelto{0}{{f_n}^{n+1}(x)}$$
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"

it's $$\displaystyle(n+1)^{th} $$ derivative is zero.
 * Recall that $$\displaystyle f_n(\cdot) $$ is a polynomial of order n ,
 * Recall that $$\displaystyle f_n(\cdot) $$ is a polynomial of order n ,
 * }
 * }


 * {| style="width:100%" border="0" align="left"

$$\displaystyle \therefore E^{n+1}(x)= f^{n+1}(x) $$
 * style="width:15%; padding:10px; border:2px solid #8888aa" |
 * style="width:15%; padding:10px; border:2px solid #8888aa" |
 * style =|
 * }
 * }

= Proof: $$ (n+1)^{th}  $$derivative  of $$q_{n+1}(x) = (n+1)! $$ = Ref: Lecture Notes [[media:Egm6341.s10.mtg12.pdf|p.12-3]]

Problem Statement
Show that
 * {| style="width:100%" border="0" align="left"

$$
 * $$\displaystyle q_{n+1}^{(n+1)}(x) = (n+1)!
 * $$\displaystyle q_{n+1}^{(n+1)}(x) = (n+1)!
 * }

Solution
From (4) in [[media:Egm6341.s10.mtg10.pdf|p.10-1]]we have:


 * {| style="width:100%" border="0" align="left"

$$ $$ q_{n+1} $$ is a n+1 polynomial, for simplicity, we express $$q_{n+1}(x)$$ as follows:
 * $$\displaystyle q_{n+1}(x) = (x-x_0)(x-x_1)\ldots (x-x_n)
 * $$\displaystyle q_{n+1}(x) = (x-x_0)(x-x_1)\ldots (x-x_n)
 * }
 * {| style="width:100%" border="0" align="left"

$$ Then the derivation of $$q_{n+1}$$ from (1) to (n+1) is shown as follows:
 * $$\displaystyle q_{n+1}(x) = x^{n+1}+c_n x^{n}+c_{n-1}x^{n-1}\ldots+ c_{1}x + c_0
 * $$\displaystyle q_{n+1}(x) = x^{n+1}+c_n x^{n}+c_{n-1}x^{n-1}\ldots+ c_{1}x + c_0
 * }
 * {| style="width:100%" border="0" align="left"

$$
 * $$\displaystyle q_{n+1}^{(1)}(x) = (n+1)x^n + nc_nx^{n-1} + (n-1)c_{n-1}x^{n-2}\ldots+c_1+0
 * $$\displaystyle q_{n+1}^{(1)}(x) = (n+1)x^n + nc_nx^{n-1} + (n-1)c_{n-1}x^{n-2}\ldots+c_1+0
 * }
 * {| style="width:100%" border="0" align="left"

$$
 * $$\displaystyle q_{n+1}^{(2)}(x) = (n+1)(n)x^{n-1} + n(n-1)c_nx^{n-2} + (n-1)(n-2)c_{n-1}x^{n-3}\ldots+0+0
 * $$\displaystyle q_{n+1}^{(2)}(x) = (n+1)(n)x^{n-1} + n(n-1)c_nx^{n-2} + (n-1)(n-2)c_{n-1}x^{n-3}\ldots+0+0
 * }
 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle \dots \dots$$
 * }
 * }


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle \dots \dots$$
 * }
 * }


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle \dots \dots$$
 * }
 * }


 * {| style="width:100%" border="0" align="left"

q_{n+1}^{(n)}(x) = (n+1)(n)(n-1)\ldots (2)x + 0 + \ldots+0+0 $$
 * $$\displaystyle
 * $$\displaystyle
 * }


 * {| style="width:100%" border="0" align="left"

$$\displaystyle \Rightarrow \ q_{n+1}^{(n+1)}(x) = (n+1)(n)(n-1)\ldots (2)(1) + 0 + \ldots+0+0 = (n+1)! $$
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style = |
 * }

= Error analysis of function $$ f(x)=log(x) $$ = Ref: Lecture notes [[media:Egm6341.s10.mtg12.pdf|p.12-3]]

Problem Statement
Consider the function $$\displaystyle f(x)=log(x) $$ and set $$\displaystyle t=2, x_{0}=3, x_{1}=4, x_{2}=5, \cdot \cdot \cdot, x_{6}=9$$.

(i) Plot $$\displaystyle f(x) $$ and $$\displaystyle f_{n}(x)$$

(ii) Plot $$\displaystyle l_{i,n} $$ when $$\displaystyle n = 3 $$.

(iii)Plot $$\displaystyle q_{n+1}(x) $$.

(iv) Obtain $$\displaystyle G(x) $$ for $$\displaystyle x = 5.5 $$.

Solution
From the problem statement, we know that $$\displaystyle n = 6 $$.

(i)

Let's construct Lagrange interpolating function.


 * {| style="width:100%" border="0" align="left"

f_{6}(x)= \sum_{i=0}^{6}l_{i,6}(x)f(x_{i}) $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (Eq. 1) $$
 * }
 * }

 Matlab code of this plots is provided in the end of this document 

Plot $$\displaystyle f(x) $$ and $$\displaystyle f_{6}(x) $$

(ii)

Let's calculate polynomial $$\displaystyle l_{3,6}(x) $$


 * {| style="width:100%" border="0" align="left"

l_{3,6}(x)=\Pi_{j=0,j \neq 3}^{6}\frac{x-x_{j}}{x_{3}-x_{j}}=\frac{(x-3)(x-4)(x-5)(x-7)(x-8)(x-9)}{(6-3)(6-4)(6-5)(6-7)(6-8)(6-9)} $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * }

 Matlab code of this plots is provided in the end of this document 

Plot $$\displaystyle l_{3,6}(x) $$

In above figure, it is extremely hard to check the behavior of $$\displaystyle l_{3,6}(x) $$ around $$\displaystyle x = x_{i} $$. Thus, we shows the plot of the same function $$\displaystyle l_{3,6}(x) $$ for $$\displaystyle x \in [3,6] $$ below.

From this figure, we can easily see the fact that $$\displaystyle l_{3,6}(x_{i}) = 0 $$ for $$\displaystyle i = 0, 1, 2, 4, 5, 6 $$ and $$\displaystyle l_{3,6}(x_{3})=1 $$.

(iii)

Let's calculate polynomial $$\displaystyle q_{n+1}(x)=q_{7}(x) $$


 * {| style="width:100%" border="0" align="left"

q_{7}(x)=\Pi_{j=0}^{6}(x-x_{j})=(x-3)(x-4)(x-5)(x-6)(x-7)(x-8)(x-9) $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * }

 Matlab code of this plots is provided in the end of this document 

Plot $$\displaystyle q_{7}(x) $$

In above figure, it is extremely hard to check the behavior of $$\displaystyle q_{7}(x) $$ around $$\displaystyle x = x_{i} $$. Thus, we shows the plot of the same function $$\displaystyle q_{7}(x) $$ for $$\displaystyle x \in [3,6] $$ below.

From this figure, we can easily see the fact that $$\displaystyle q_{7}(x_{i}) = 0 $$ for all $$\displaystyle i $$.

(iv)

 Matlab code of the calculations in this part is provided in the end of this document 

Recall that $$\displaystyle G(x) $$ can be calculated by the following equation:


 * {| style="width:100%" border="0" align="left"

G(x)=E(x)-\frac{q_{7}(x)}{q_{7}(t)}E(t) $$
 * $$\displaystyle
 * $$\displaystyle
 * }
 * }

Since $$\displaystyle t=2 $$ and $$\displaystyle x=5.5 $$,

$$\displaystyle E(x)=9.460393681548496e-006 $$, $$\displaystyle E(t)=-8.949684549653392e-003 $$,

$$\displaystyle q_{7}(x)=1.230468750000000e+001 $$ and $$\displaystyle q_{7}(t)=-5040 $$.

Therefore,


 * {| style="width:100%" border="0" align="left"

$$\displaystyle G(x) = -1.238942211350373e-005 $$
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style = |
 * }
 * }
 * }

 Matlab code for (i), (ii), (iii) and (iv) 

Error calculation: Simple Trapezoidal rule
Ref: Lecture Notes [[media:Egm6341.s10.mtg13.pdf|p.13-2]]

Problem Statement
Show that $$ \left| {E}_{1}\right| \leq \frac{M_{2}}{2!}\int_{a}^{b}\left | q_{2}(x) \right | dx = \frac{{M}_{2}}{2!}\int_{a}^{b}(x-a)(b-x) dx = \frac{{(b-a)}^{3}}{12}{M}_{2} = \frac{h^{3}}{12}M_{2} $$

where $$ \displaystyle h:= b-a $$

Solution
Expansion $$ \displaystyle (x-a)(b-x) $$

$$ \frac{{M}_{2}}{2!}\int_{a}^{b}(x-a)(b-x) dx = -\frac{{M}_{2}}{2!}\int_{a}^{b}\left \{ x^{2}-(a+b)x+ab \right \}dx $$

Integrating $$ \displaystyle \left \{ x^{2}-(a+b)x+ab \right \} $$

$$ = -\frac{{M}_{2}}{2!}\left [ \left \{ \frac{1}{3}b^{3}-\frac{1}{2}(a+b)b^{2}+ab^{2} \right \}-\left \{ \frac{1}{3}a^{3}-\frac{1}{2}(a+b)a^{2}+a^{2}b \right \} \right ] $$

$$ = -\frac{{M}_{2}}{2!6}(-b^{3}+3ab^{2}-3a^{2}b+a^{3}) $$

$$ = \frac{{M}_{2}}{2!6}(b^{3}-3ab^{2}+3a^{2}b-a^{3}) $$

$$ = \frac{M_{2}}{12}\underbrace {(b-a)^{3}}_{by Binomial Theorem} $$

Therefore,
 * {| style="width:100%" border="0" align="left"

$$\displaystyle \left| {E}_{1}\right| \leq \frac{M_{2}}{2!}\int_{a}^{b}\left | q_{2}(x) \right | dx = \frac{{M}_{2}}{2!}\int_{a}^{b}(x-a)(b-x) dx = \frac{{(b-a)}^{3}}{12}{M}_{2} = \frac{h^{3}}{12}M_{2} $$
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style = |
 * }
 * }

--Heejun Chung 23:50, 20 February 2010 (UTC)

Error calculation: Simple Simpson rule
Ref: Lecture Notes [[media:Egm6341.s10.mtg13.pdf|p.13-2]]

Problem Statement
Show that $$ \left| {E}_{n}\right| \leq \frac{{M}_{3}}{3!}\int_{a}^{b}\left|(x-a)(x-\frac{a+b}{2})(x-b) \right| dx = \frac{{(b-a)}^{4}}{196}{M}_{3} = \frac{{2}^{4}{h}^{4}}{196}{M}_{3} $$

where $$ h:=\frac{b-a}{2} \Rightarrow b-a = 2h $$

Solution
Determination the range at $$ \displaystyle {(x-a)(x-\frac{(a+b)}{2})(x-b)} $$ always $$ \displaystyle \geq 0 $$

$$ \frac{{M}_{3}}{3!}\int_{a}^{b} \left|(x-a)(x-\frac{(a+b)}{2})(x-b) \right| dx $$

$$ = \frac{{M}_{3}}{3!}\left[\int_{a}^{\frac{(a+b)}{2}}(x-a)(\frac{(a+b)}{2} - x)(b-x)dx + \int_{\frac{(a+b)}{2}}^{b}(x-a)(x-\frac{(a+b)}{2})(b-x)dx \right] $$

$$ = \frac{{M}_{3}}{3!}\left[\underbrace {\int_{a}^{\frac{(a+b)}{2}}(x-a)(x-\frac{(a+b)}{2})(x-b)dx}_{call {P}_{1}} - \underbrace {\int_{\frac{(a+b)}{2}}^{b}(x-a)(x-\frac{(a+b)}{2})(x-b)dx}_{call {P}_{2}}\right] $$

Integrating $$ \displaystyle P_{1} $$

$$ \int_{a}^{\frac{(a+b)}{2}}(x-a)(x-\frac{(a+b)}{2})(x-b)dx $$

$$ = \frac{1}{4}(\frac{a+b}{2})(\frac{-a-b}{2})(\frac{{a}^{2}+2ab+{b}^{2}}{4}-\frac{{a}^{2}+2ab+{b}^{2}}{2}+2ab)-\frac{1}{4}a(-b)({a}^{2}-{a}^{2}-ab+2ab) $$

$$ = -\frac{1}{4}\times\frac{{(a+b)}^{2}}{4}\times \frac{{-(a-b)}^{2}+4ab}{4}+\frac{{a}^{2}{b}^{2}}{4} $$

$$ = -\frac{1}{{4}^{3}} {(a+b)}^{2} \left[ 4ab-{(a-b)}^{2} \right] +\frac{{a}^{2}{b}^{2}}{4} $$

Integrating $$ \displaystyle P_{2} $$

$$ \int_{\frac{(a+b)}{2}}^{b}(x-a)(x-\frac{(a+b)}{2})(x-b)dx $$

$$ = -\frac{{a}^{2}{b}^{2}}{4} + \frac{1}{{4}^{3}}{(a+b)}^{2}\left[ 4ab-{(a-b)}^{2} \right] $$

Computing $$ \displaystyle P_{1}-P_{2} $$

$$ \begin{align} P_{1}-P_{2} &= \frac{a^{2}b^{2}}{2}+\frac{(a+b)^{2}}{4^{3}}\left [ 2(a-b)^{2}-8ab \right ] \\ &=\frac{1}{32} \left [ (a^{4}+b^{4})-4ab(a^{2}+b^{2})+6a^{2}b^{2} \right ] \\ &=\frac{1}{32} \underbrace{(a^{4}-4a^{3}b+6a^{2}b^{2}-4ab^{3}+b^{4})}_{by Binomial Thereom}\\ &=\frac{(a-b)^{4}}{32} = \frac{(b-a)^{4}}{32}\\\end{align}\ $$

Therefore,
 * {| style="width:100%" border="0" align="left"

$$\displaystyle \displaystyle I=\frac{M_{3}}{3!}(P_{1}-P_{2}) = \frac{M_{3}}{3!} \frac{(b-a)^{4}}{32} = \frac{M_{3}}{192}(b-a)^{4} $$
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style = |
 * }
 * }

--Heejun Chung 23:51, 20 February 2010 (UTC)

=Proof: Simpson's rule integrates a $$3^{rd}$$ order polynomial exactly= Ref: Lecture notes [[media:Egm6341.s10.mtg13.pdf|p.13-3]]

Problem Statement

 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle f_3(x) = P_3(x) = c_0 + c_1x + c_2x^2 + c_3x^3$$   $$\in [a,b] = [0,1] $$
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle c_0=3,$$ $$\displaystyle c_1=8,$$  $$\displaystyle c_2=-2, \, c_3 =6.$$
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"

$$ \displaystyle Compare\, the\, results.$$
 * $$\displaystyle Find\, I\, and\, I_2 \,using\, Simpson's\, rule.$$
 * $$\displaystyle Find\, I\, and\, I_2 \,using\, Simpson's\, rule.$$
 * }
 * }

Solution
Given:
 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle P_3(x) = 3+ 8x -2x^2 + 6x^3 $$
 * <p style="text-align:right;">$$\displaystyle (Eq. 1) $$
 * }
 * }
 * }

EXACT INTEGRAL Integrating Eq (1),


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle I = \int_{a}^{b} \Bigg(3+ 8x -2x^2 + 6x^3\Bigg)\,dx $$
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"

$$\displaystyle = \int_{0}^{1} \Big(3+ 8x -2x^2 + 6x^3\Big)\,dx $$
 * }
 * }


 * {| style="width:100%" border="0" align="left"

$$\displaystyle =\Big[ 3x + 4x^2 - \frac{2x^3}{3} + \frac{3x^4}{2} \Big]_0^1 $$
 * }
 * }


 * {| style="width:100%" border="0" align="left"

$$\displaystyle = \Big[ 3 +4 - \frac{2}{3} + \frac{3}{2}\Big]$$
 * }
 * }


 * {| style="width:100%" border="0" align="left"

$$\displaystyle = \frac{47}{6} $$
 * }
 * }


 * {| style="width:100%" border="0" align="left"

$$\displaystyle \therefore I = 7.8333$$
 * style="width:15%; padding:10px; border:2px solid #8888aa" |
 * style="width:15%; padding:10px; border:2px solid #8888aa" |
 * style = |
 * }
 * }

SIMPSON'S RULE We know from lecture slide Eq(2) [[media:Egm6341.s10.mtg7.pdf|p.7-2]] that the Simple Simpson's Rule is given by,


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle I_2 = \frac{h}{3}\bigg[ f(x_0)+ 4f(x_1)+ f(x_2)\bigg]$$
 * <p style="text-align:right;">$$\displaystyle (Eq. 2) $$
 * }
 * }
 * }

where,


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle x_0\, = a\,=0 $$
 * <p style="text-align:right;">$$\displaystyle (Eq. 3) $$
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle x_2\, = b\,=1 $$
 * <p style="text-align:right;">$$\displaystyle (Eq. 4) $$
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle x_1\, = \frac{a+b}{2}\,= \frac{1}{2} $$
 * <p style="text-align:right;">$$\displaystyle (Eq. 5) $$
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle h\, = \frac{b-a}{2}\,= \frac{1}{2} $$
 * <p style="text-align:right;">$$\displaystyle (Eq. 6) $$
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle f(x_0)\, = \Big[ 3 + 4(0) - 2\cdot(0)^2 + 6\cdot(0)^3 \Big]\,= 3 $$
 * <p style="text-align:right;">$$\displaystyle (Eq. 7) $$
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle f(x_1)\, = \Big[ 3 + 4(0.5) - 2\cdot(0.5)^2 + 6\cdot(0.5)^3 \Big]\,= 7.25 $$
 * <p style="text-align:right;">$$\displaystyle (Eq. 8) $$
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle f(x_2)\, = \Big[ 3 + 4(1) - 2\cdot(1)^2 + 6\cdot(1)^3 \Big]\,= 15 $$
 * <p style="text-align:right;">$$\displaystyle (Eq. 9) $$
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle \therefore\, Substituting\, Eq (6)\, through\, Eq (9)\, in\, Eq(2)\, we\, have\,$$
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle I_2 = \frac{1}{6}\bigg[ 3+ 29 + 15 \bigg] =\, \frac{47}{6} $$
 * }
 * }
 * }


 * {| style="width:100%" border="0" align="left"

$$\displaystyle \therefore I_2 = 7.8333$$
 * style="width:15%; padding:10px; border:2px solid #8888aa" |
 * style="width:15%; padding:10px; border:2px solid #8888aa" |
 * style =|
 * }
 * }
 * {| style="width:100%" border="0" align="left"


 * $$\displaystyle Since\, I = I_2\, it\, is\, very\, clear\, that\, the\, Simpson\, rule\, integrates\, a\, 3^{rd}\, order\, polynomial\, exactly $$
 * }
 * }
 * }

= Derivation : $$\alpha^{(1)}(t) = F(-t) + F(t)$$ in Simple Simpson's rule= Ref: Lecture Notes [[media:Egm6341.s10.mtg15.pdf|p.15-1]]

Problem Statement
Show that
 * {| style="width:100%" border="0" align="left"

$$
 * $$\displaystyle \alpha^{(1)}(t)= F(-t) + F(t)
 * $$\displaystyle \alpha^{(1)}(t)= F(-t) + F(t)
 * style = |
 * }

Solution
From (4) in [[media:Egm6341.s10.mtg14.pdf|p.14-2]], we can write down the expression of $$ \alpha(t) $$

$$ \alpha(t) = \int_{-t}^t f(x(t))\, dt $$

Given :

f(x(t)) = F(t)

Let there exists $$ g^1(t)= F(t) $$

$$ \alpha(t) = \int_{-t}^t f(x(t))\, dt

= \int_{-t}^t F(t))\, dt

= \int_{-t}^t g^1(t))\, dt

= g(t)- g(-t) $$

$$  \alpha^{(1)}(t) = \frac{d}{dt}[g(t)- g(-t)] $$

$$ \Rightarrow \alpha^{(1)}(t) = g^1(t)- (-g^1(-t)) $$

but $$ g^1(t)= F(t) $$

$$ \Rightarrow \alpha^{(1)}(t) = F(t)+F(-t)) $$

Hence Proved ,

= Proof: $$ G^{(2)}(0)=0 $$ in Simpson's Rule = Ref: Lecture notes [[media:Egm6341.s10.mtg15.pdf|p.15-2]]

Problem Statement
For the Simpson's rule, prove that $$\displaystyle G^{(2)}(0)=0 $$.

Solution
From [[media:Egm6341.s10.mtg14.pdf|p.14-3]] of lecture note, $$\displaystyle G(t) $$ can be expressed by:


 * {| style="width:100%" border="0" align="left"

G(t) = e(t)-t^{5}e(1) $$
 * $$\displaystyle
 * $$\displaystyle
 * <p style="text-align:right;">$$\displaystyle (Eq. 1) $$
 * }
 * }

where
 * {| style="width:100%" border="0" align="left"

e(t)=\alpha(t)-\alpha_{2}(t)=\int_{-t}^{t}F(s)ds - \frac{t}{3}[F(-t)+4F(0)+F(t)] $$
 * $$\displaystyle
 * $$\displaystyle
 * <p style="text-align:right;">$$\displaystyle (Eq. 2) $$
 * }
 * }

From [[media:Egm6341.s10.mtg15.pdf|p.15-1]] of lecture note, we already get the first derivatives of $$\displaystyle \alpha(x) $$ and $$\displaystyle \alpha_{2}(x) $$:


 * {| style="width:100%" border="0" align="left"

\alpha^{(1)}(t)=F(-t)+F(t) $$
 * $$\displaystyle
 * $$\displaystyle
 * <p style="text-align:right;">$$\displaystyle (Eq. 3) $$
 * }
 * }


 * {| style="width:100%" border="0" align="left"

\alpha_{2}^{(1)}(t)=\frac{1}{3}[F(-t)+4F(0)+F(t)]+\frac{t}{3}[F^{(1)}(-t)+F^{(1)}(t)] $$
 * $$\displaystyle
 * $$\displaystyle
 * <p style="text-align:right;">$$\displaystyle (Eq. 4) $$
 * }
 * }

From the Eq.(3) and Eq.(4), we can obtain the second derivatives of $$\displaystyle \alpha(x) $$ and $$\displaystyle \alpha_{2}(x) $$:


 * {| style="width:100%" border="0" align="left"

\alpha^{(2)}(t)=F^{(1)}(-t)+F^{(1)}(t) $$
 * $$\displaystyle
 * $$\displaystyle
 * <p style="text-align:right;">$$\displaystyle (Eq. 5) $$
 * }
 * }


 * {| style="width:100%" border="0" align="left"

\alpha_{2}^{(2)}(t)=\frac{2}{3}[F^{(1)}(-t)+F^{(1)}(t)]+\frac{t}{3}[F^{(2)}(-t)+F^{(2)}(t)] $$
 * $$\displaystyle
 * $$\displaystyle
 * <p style="text-align:right;">$$\displaystyle (Eq. 6) $$
 * }
 * }

From the Eq.(1), the second derivative of $$\displaystyle G(t) $$ is


 * {| style="width:100%" border="0" align="left"

G^{(2)}(t) = e^{(2)}(t)-20t^{3}e(1) = \alpha^{(2)}(t)-\alpha_{2}^{(2)}(t)-20t^{3}e(1) $$
 * $$\displaystyle
 * $$\displaystyle
 * <p style="text-align:right;">$$\displaystyle (Eq. 7) $$
 * }
 * }

Plug Eq.(5) and Eq.(6) into Eq.(7).


 * {| style="width:100%" border="0" align="left"

G^{(2)}(t) = \frac{1}{3}[F^{(1)}(-t)+F^{(1)}(t)]-\frac{t}{3}[F^{(2)}(-t)+F^{(2)}(t)]-20t^{3}e(1) $$
 * $$\displaystyle
 * $$\displaystyle
 * <p style="text-align:right;">$$\displaystyle (Eq. 8) $$
 * }
 * }

Now, let's explicitly express $$\displaystyle F^{(1)}(t) $$ and $$\displaystyle F^{(1)}(t) $$ as follows.


 * {| style="width:100%" border="0" align="left"

F^{(1)}(t) = \frac{dF(t)}{dt} $$
 * $$\displaystyle
 * $$\displaystyle
 * <p style="text-align:right;">$$\displaystyle (Eq. 9) $$
 * }
 * }

For the expression of the derivation of $$\displaystyle F^{(1)}(-t) $$, let $$\displaystyle -t=\tau $$ and use chain rule.


 * {| style="width:100%" border="0" align="left"

F^{(1)}(-t) = F^{(1)}(\tau)=\frac{dF(\tau)}{dt}=\frac{d\tau}{dt}\frac{dF(\tau)}{d\tau}=(-1)\frac{dF(\tau)}{d\tau} $$
 * $$\displaystyle
 * $$\displaystyle
 * <p style="text-align:right;">$$\displaystyle (Eq. 10) $$
 * }
 * }

Now, Plug Eq.(9) and Eq.(10) into Eq.(8). Then,


 * {| style="width:100%" border="0" align="left"

G^{(2)}(t) = \frac{1}{3}[(-1)\frac{dF(\tau)}{d\tau}+\frac{dF(t)}{dt}]-\frac{t}{3}[F^{(2)}(-t)+F^{(2)}(t)]-20t^{3}e(1) $$
 * $$\displaystyle
 * $$\displaystyle
 * <p style="text-align:right;">$$\displaystyle (Eq. 11) $$
 * }
 * }

To obtain $$\displaystyle G^{(2)}(0) $$, note that $$\displaystyle t=0 \rightarrow \tau=0 $$ and the second and the third terms of RHS in Eq.(11) are going to be zero when $$\displaystyle t=0 $$. Then,


 * {| style="width:100%" border="0" align="left"

G^{(2)}(0) = \frac{1}{3}[(-1)\left(\frac{dF(\tau)}{d\tau}\right)_{\tau=0}+\left(\frac{dF(t)}{dt}\right)_{t=0}] - 0 - 0 $$
 * $$\displaystyle
 * $$\displaystyle
 * <p style="text-align:right;">$$\displaystyle (Eq. 12) $$
 * }
 * }


 * {| style="width:100%" border="0" align="left"

\Rightarrow G^{(2)}(0) = \frac{1}{3}[(-1)F^{(1)}(0)+F^{(1)}(0)] $$
 * $$\displaystyle
 * $$\displaystyle
 * <p style="text-align:right;">$$\displaystyle (Eq. 13) $$
 * }
 * }

Therefore,


 * {| style="width:100%" border="0" align="left"

$$\displaystyle G^{(2)}(0) = 0 $$
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style = |
 * <p style="text-align:right;">$$\displaystyle (Eq. 14) $$
 * }
 * }

= Proof:$$ e^3(t) = -(t/3) * [F^3(t)- F^3(-t)]$$ in Simple Simpson's rule =

Ref Lecture [[media:Egm6341.s10.mtg15.pdf|p.15-2]]

Problem Statement
Prove that

$$ e^{(3)}(t) = - \frac{t}{3}[F^{(3)}(t)- F^{(3)}(-t)]$$

where

$$ e(t)= \int_{-t}^t f(x(t))\, dt - \frac {t}{3}[F(-t)+4 F(0)+F(t)] $$

Solution
$$ e(t)= \int_{-t}^t f(x(t))\, dt - \frac {t}{3}[F(-t)+4 F(0)+F(t)] $$

$$ e(t)= \int_{-t}^k f(x(t))\, dt +\int_{k}^t f(x(t))\, dt - \frac {t}{3}[F(-t)+4 F(0)+F(t)] $$

$$ e^{(1)}(t)= (F(-t)+F(t)) - \frac {t}{3}[- F^1(-t)+F^1(t)] - \frac {1}{3}[F(-t)+4 F(0)+F(t)] $$

$$ e^{(2)}(t)= (-F^1(-t)+F^1(t)) - \frac {t}{3}[ F^2(-t)+F^2(t)] - \frac {1}{3}[-F^1(-t)+F^1(t)]-\frac {1}{3}[-F^1(-t)+F^1(t)] $$

$$ e^{(2)}(t)= (-F^1(-t)+F^1(t)) - \frac {t}{3}[ F^2(-t)+F^2(t)] - \frac {2}{3}[-F^1(-t)+F^1(t)] $$

$$ e^{(3)}(t)= (F^2(-t)+F^2(t)) - \frac {t}{3}[- F^3(-t)+F^3(t)] -\frac {1}{3}[F^2(-t)+F^2(t)]- \frac {2}{3}[F^2(-t)+F^2(t)] $$ $$ e^{(3)}(t)= (F^2(-t)+F^2(t)) - \frac {t}{3}[- F^3(-t)+F^3(t)] -(F^2(-t)+F^2(t)) $$

$$ e^{(3)}(t)= - \frac {t}{3}[- F^3(-t)+F^3(t)] $$

$$ e^{(3)}(t)= - \frac {t}{3}[ F^3(t)-F^3(-t)] $$

Hence Proved ..

Relationship between $$ \xi $$ and $$ \zeta_{4} $$ in Simple Simpson's rule
Ref: Lecture Notes [[media:Egm6341.s10.mtg15.pdf|p.15-3]]

Problem Statement
Given that$$ -\frac{1}{90}F^{(4)}(\zeta _{4})=-\frac{(b-a)^{4}}{1440}f^{(4)}(\xi) $$ Find the relationship between $$\zeta _{4}$$ and $$ \xi $$

Solution
Use chain Rule

$$ \displaystyle F(t)=f(x) $$

$$ \displaystyle x(t)=x_{1}+ht $$

$$ \displaystyle F^{(1)}(t)=\frac{dF(t)}{dt} = \frac{df(x)}{dx}\frac{dx}{dt} = f^{(1)}(x) \times h = hf^{(1)}(x) $$

$$ \because \frac{d\left(x(t)\right)}{dt} = \frac{d(x_{1}+ht)}{dt} = h $$

$$ \displaystyle F^{(2)}(t) = \frac{d\left(F(t)^{(1)}\right)}{dt} = \frac{d\left(hf(x)^{(1)}\right)}{dx}\frac{dx}{dt} = hf^{(2)}(x) \times h = h^{2}f^{(1)}(x) $$

$$ \displaystyle F^{(3)}(t) = \frac{d\left(F(t)^{(2)}\right)}{dt} = \frac{d\left(h^{2}f(x)^{(2)}\right)}{dx}\frac{dx}{dt} = h^{2}f^{(3)}(x) \times h = h^{3}f^{(3)}(x) $$

$$ \displaystyle F^{(4)}(t) = \frac{d\left(F(t)^{(3)}\right)}{dt} = \frac{d\left(h^{3}f(x)^{(3)}\right)}{dx}\frac{dx}{dt} = h^{3}f^{(4)}(x) \times h = h^{4}f^{(4)}(x) $$

Now, obtain the relationship between $$ \displaystyle \xi $$ and $$ \displaystyle \zeta_{4} $$

$$ \displaystyle x(\zeta_{4}) = x_{1} + h\zeta_{4} = \xi $$

And recall that $$ \displaystyle h=\frac{b-a}{2} $$ Then,

$$ \displaystyle -\frac{1}{90}F^{(4)}(\zeta _{4})=-\frac{1}{90}\left(h^{4}f^{(4)}(\xi)\right)=-\frac{1}{90}\left(\frac{(b-a)^{4}}{2^{4}}f^{(4)}(\xi)\right) $$

Therefore,
 * {| style="width:100%" border="0" align="left"

$$\displaystyle -\frac{1}{90}F^{(4)}(\zeta _{4})=-\frac{(b-a)^{4}}{1440}f^{(4)}(\xi) $$
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style = |
 * }
 * }

where


 * {| style="width:100%" border="0" align="left"

$$\displaystyle \xi = x_{1}+h \zeta_{4} $$
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style="width:10%; padding:10px; border:2px solid #8888aa" |
 * style = |
 * }
 * }

--Heejun Chung 23:52, 20 February 2010 (UTC)

=Runge Phenomenon - Motivation for composite Rules= Ref: Lecture notes [[media:Egm6341.s10.mtg16.pdf|p.16-1]]

Problem Statement

 * {| style="width:100%" border="0" align="left"

$$\displaystyle I = \int_{-5}^{5}f(x)\, dx $$
 * $$\displaystyle f(x) = \frac{1}{1+x^2}$$
 * $$\displaystyle f(x) = \frac{1}{1+x^2}$$
 * }
 * }

(i) Using Newton-Cotes obtain $$ I_n $$ for n==1,2,.......,15. (ii) Plot f(x) and$$\, f_n(x)$$ for n=1,2,3,8 and 12. (iii)Plot $$I_n\;vs\;n.$$. Comment on the pattern. (iv)Plot the Lagrange basis functions $$l_{i,n} $$ for n=8 and i=1,2......8.

Solution
EXACT INTEGRAL


 * {| style="width:100%" border="0" align="left"

$$\displaystyle = \int_{-5}^{5}\frac{1}{1+x^2}\, dx $$ $$\displaystyle = \Big[tan^{-1} (x)\Big]_{-5}^{5} =\;2.7468 $$
 * $$\displaystyle I = \int_{-5}^{5}f(x)\, dx $$
 * $$\displaystyle I = \int_{-5}^{5}f(x)\, dx $$
 * }
 * }


 * {| style="width:100%" border="0" align="left"

$$\displaystyle \therefore\, I = 2.7468 $$
 * style="width:15%; padding:10px; border:2px solid #8888aa" |
 * style="width:15%; padding:10px; border:2px solid #8888aa" |
 * style =|
 * }
 * }

MATLAB Code that will generate the Lagrange Basis Functions, $$\displaystyle I_n\, and\, f_n(x)$$ for any given n

(i) $$\displaystyle I_n $$ obtained using Newton-Cotes formula for n=1,2,.....,15. Results: Comparison of $$\displaystyle I_n\, vs\, n $$

(ii) $$\displaystyle Plot\,:\,I_n\, vs\, n$$

As it can be observed from the plot, we find that the value of $$I_n$$ never converges as n increases. This is called as the Runge phenomenon. And for this reason composite rules are preferred.

(iii) $$\displaystyle Plot\,:\,f(x)\, and\, f_n(x)\,for\, n=1,\,2,\, 3,\, 8,\, and \, 12.$$  f(x) vs x

$$\displaystyle Plot:\, f_1(x)\, vs\, x $$

$$\displaystyle Plot:\, f_2(x)\, vs\, x $$

$$\displaystyle Plot:\, f_3(x)\, vs\, x $$

$$\displaystyle Plot:\, f_8(x)\, vs\, x $$

$$\displaystyle Plot:\, f_12(x)\, vs\, x $$

(iii) $$\displaystyle Plot\,:\,l_{i,n}\, for\, n=8\, and\, i=\,0,\,1,\,.....\,8.$$

$$\displaystyle Plot\,:\,l_{i,n}\, for\, n=8\, and\, i=\,0,\,1,\,and\,2.$$

$$\displaystyle Plot\,:\,l_{i,n}\, for\, n=8\, and\, i=\,3,\,4,\,and\,5.$$

$$\displaystyle Plot\,:\,l_{i,n}\, for\, n=8\, and\, i=\,6,\,7,\,and\,8.$$

= Contributing Team Members = Subramanian Annamalai 20:38, 10 February 2010 (UTC)

Yong Nam Ahn 09:19, 10 February 2010 (UTC)

Min Zhong 12:24, 10 February (UTC)

Abhishek k singh 19:12, 10 February (UTC)

Heejun Chung 13:15, 10 February (UTC)

=References= 1. Introduction to Numerical Methods,2nd Edition by Kendall E Atkinson Second Edition 2. Numerical Methods for Engineers,5th Edition by Steven C Chapra and Raymond P Canale