User:Egm6341.s10.team4.anandankala/HW2-3

=Problem 3=

Given

 * {| style="width:70%" border="0" align="center"



f(x) = \frac{e^x - 1}{x} on the interval [0,1]. $$
 * $$\displaystyle

Consider n=0,1,2,4,8,16.
 * $$\displaystyle $$


 * }.
 * }.

Find

 * {| style="width:70%" border="0" align="center"



Construct $$ \displaystyle f_n(x)= \sum_{i=0}^n l_{i,n}(x)f(x_i)$$

a) Plot $$ \displaystyle f,f_n, n=1,2,4,8,16. $$

b) Compute $$ I_n= \int_{a}^{b}f_n(x)dx, n=1,2,4,8,16. $$

c) Plot $$ \displaystyle l_0, l_1, l_2, for n=4 $$


 * $$\displaystyle $$
 * }.
 * }.

Solution
From Newton Cotes formula, we have $$ \displaystyle f_n(x)= \sum_{i=0}^n l_{i,n}(x)f(x_i)$$

$$\displaystyle l_{i,n}(x)= \displaystyle\prod_{\underset{j\neq i}{j=0}}^{N}\frac{x-x_j}{x_i-x_j}$$

fn(x) has been constructed using matlab and its plots are shown below

Matlab Code: Plots:

.

The function f(x) has been plotted and the plot is shown below:

Plot of f(x)

.

The value of In has been computed for different values of n in matlab and the details are tabulated below:

$$\begin{array}{|c||c|c|c|c|c|c|c|c|c|c|c}\hline n & 1 & 2 & 4 & 8 & 16 \\ \hline I_n&1.3591&1.3180&1.3179&1.3179&1.3179\\ \hline \end{array} $$.

For n=4, the plots of $$l_0,l_1,l_2$$ are shown below including the matlab code:

Matlab Code:

Plots:

.

.

.

.

.

Comments:
The plots of l3,l4 need not be plotted since they are the mirror images of the plots of l1,l0 respectively.