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

= (8) 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)