User:Egm6341.s10.team3.ynahn81/HW2-3

= (3) Newton-Cotes Method for $$ f(x)=\frac{e^{x}-1}{x} $$ = 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) = \Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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}=\Pi_{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.