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

=Problem 3=

Given

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

$$I=\int\limits_{0}^{1} f(x)\, dx$$

$$where f(x)=\frac{(e^x-1)}{x}.$$
 * $$\displaystyle $$
 * }.
 * }.

Find

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


 * 1) Find n such that En=I-In is of the order of 10-6 using the error estimates for the Taylor's series, composite Trapezoidal rule, composite Simpson's rule and compare to numerical results.
 * 2) Numerically find the power of h in the error. Plot error versus h on log graph and measure slope.
 * 1) Find n such that En=I-In is of the order of 10-6 using the error estimates for the Taylor's series, composite Trapezoidal rule, composite Simpson's rule and compare to numerical results.
 * 2) Numerically find the power of h in the error. Plot error versus h on log graph and measure slope.


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

Solution
The error for Taylor series is analytically given by $$\displaystyle \frac{1}{(n+1)!(n+1)} \leq E_n \leq \frac{e}{(n+1)!(n+1)}$$

The maximum value of En is equal to $$\displaystyle \frac{e}{(n+1)!(n+1)} $$.

The value of the error given in the problem is equal to 10-6.


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




 * $$\Rightarrow \displaystyle \frac{e}{(n+1)!(n+1)}= 10^{-6} $$
 * }.
 * }.


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




 * $$\Rightarrow \displaystyle (n+1)!(n+1)= e \cdot10^6 $$
 * }.
 * {| style="width:70%" border="0" align="center"
 * {| style="width:70%" border="0" align="center"




 * $$\Rightarrow \displaystyle n=8(approximately). $$
 * }.
 * }.

The error for composite Trapezoidal rule is analytically given by $$\displaystyle |E^1_n| \leq \frac{(b-a)^3}{12n^2}M_2$$

where M2 is the maximum of $$\displaystyle f^{''}(x).$$ in the interval [0,1]. $$\Rightarrow a=0,b=1.$$


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




 * Given $$\displaystyle f(x)=\frac{(e^x-1)}{x}.$$


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




 * $$\Rightarrow f^'(x)=\frac {xe^x-e^x+1}{x^2}.$$


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




 * $$\Rightarrow f^{''}(x)=\frac {x^2e^x-2xe^x+2e^x-2}{x^3}$$

Plot:
 * }.
 * }.

.

The above function $$\displaystyle f^{''}(x)$$ is plotted with respect to x in the interval [0,1] and a maximum of 0.72 is obtained at x=1.


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




 * $$\Rightarrow \displaystyle |E^1_n|=\frac{(b-a)^3}{12n^2}M_2=\frac{M_2}{12n^2}$$


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




 * $$\Rightarrow \displaystyle \frac{M_2}{12n^2}=10^{-6}$$


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




 * $$\Rightarrow \displaystyle n^2=\frac{0.72*10^6}{12}$$


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




 * $$\Rightarrow \displaystyle n=245$$(approximately).


 * }.
 * }.

The error for composite Simpson's rule is analytically given by $$\displaystyle |E^2_n| \leq \frac{(b-a)^5}{180n^4}M_4.$$

where M4 is the maximum of $$\displaystyle f^4(x).$$ in the interval [0,1].


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




 * Given $$\displaystyle f(x)=\frac{(e^x-1)}{x}.$$


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




 * $$\Rightarrow f^4(x)=\frac {x^4e^x-4x^3e^x+12x^2e^x-24xe^x+24e^x-24}{x^5}.$$


 * }.
 * }.

Plot:

.

The above function $$\displaystyle f^4(x)$$ is plotted with respect to x in the interval [0,1] and a maximum of 0.465 is obtained at x=1.


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




 * $$\Rightarrow \displaystyle |E^2_n|=\frac{(b-a)^5}{180n^4}M_4=\frac{M_4}{180n^4}.$$


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




 * $$\Rightarrow \displaystyle \frac{M_4}{180n^4}=10^{-6}$$


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




 * $$\Rightarrow \displaystyle n^4=\frac{0.465*10^6}{180}$$


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




 * $$\Rightarrow \displaystyle n=8$$(approximately).


 * }.
 * }.

The above analytical values of n are compared to the numerical values of n for an error of 10-6 which in turn are obtained from the matlab code.

 Matlab Code: for $$ E_{Taylors series} $$ 

 Matlab Code: for $$ E_{n,Trapezoidal} $$ 

 Matlab Code: for $$ E_{n,simpson} $$ 

The values of n obtained numerically for an error of 10-6 are 8,200,8 for Taylors series,trapezoidal rule and Simpson's rule which are almost equal to the values 8,245,8 found analytically.

In the next part we are required to find the convergence of the error and power of h in the error numerically. Hence we plot the values of the error and h on a log plot or alternatively plot the values of log(Error) and log(h) in excel plot using the numerical values.

Semilog Plot:

.

Semilog Plot:

.

Logarithmic Plot:

.

The slope of the line in the above graph is obtained to be equal to 2. This is the required power of h in the error formula for trapezoidal rule.

Semilog Plot:

.

Logarithmic Plot:

.

The slope of the line in the above graph is obtained to be equal to 4. This is the required power of h in the error formula for simpsons rule.