User:Egm6341.s11.team4.fields/HW5.6

=Problem 5.6: Computation of In using CTk(n)=

Refer to lecture slide [[media:nm1.s11.mtg30.djvu|30-1]] for the problem statement.

Given

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



(6.1)
 * $$\displaystyle I:=\int_{a}^{b}\underbrace{\frac{e^x-1}{x}}_{f(x)}dx$$
 * 
 * }
 * }

For


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




 * $$\displaystyle a = -1$$


 * }
 * }

and


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




 * $$\displaystyle b = 1$$


 * }
 * }

Corrected Trapezoidal Rule:


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



(6.2)
 * $$\displaystyle CT_k(n) = CT_{k-1}(n) + a^0_kh^{2k} + O(h^{2(k+1)})$$
 * 
 * }
 * }

Where


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



(6.3)
 * $$\displaystyle a_i^0 = d_i \left[ f^{(2i-1)}(b) - f^{(2i-1)}(a) \right]$$
 * 
 * }
 * }

and


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




 * $$\displaystyle h = \frac{b-a}{n}$$


 * }
 * }

Composite Trapezoidal Rule:


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



(6.4)
 * $$\displaystyle CT_{0}(n) = T_0(n) = \frac{b-a}{n} \left[ \frac{1}{2}f_0 + f_1 + \ldots + f_{n-1} + \frac{1}{2}f_n \right]$$
 * 
 * }
 * }

Where


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




 * $$\displaystyle d_i = -B_{2i}/(2i)!$$


 * }
 * }

and


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




 * $$\displaystyle B_{i} = Bernoulli Number$$


 * }
 * }

Objective
a.) Compute In using CTk(n), for k = 1 and n = 2, 4, 8, 16, ... until error is of order 10-6

b.) Compute In using CTk(n), for k = 2 and n = 2, 4, 8, 16, ... until error is of order 10-6

c.) Compute In using CTk(n), for k = 3 and n = 2, 4, 8, 16, ... until error is of order 10-6

Solution
Using Wolfram Alpha we find that the exact value of the integral to 12 significant digits is:

I = 2.11450175075

a.) Compute In using CTk(n) for k = 1
Using equations 6.2, 6.3 and 6.4 we compute CT1(n)


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



(6.5)
 * $$\displaystyle CT_1(n) = T_0(n) + a^0_1h^{2} + O(h^{4})$$
 * 
 * }
 * }


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




 * $$\displaystyle a^0_1 = d_1 \left[ f^{(1)}(1) - f^{(1)}(-1) \right] = \frac{-1}{12}\left[1 - 0.264241117657 \right] =    -0.0613132401952$$


 * }
 * }

The MatLab code below was used for different values of n to generate the following table:

function [CTk1,Enk1] = CorTrapk1(a,b,n) %Corrected Trapezoidal Rule for k = 1 %  f(x) = (e^x - 1)/x

h = (b - a)/n; ni = n+1; I = 2.11450175075; a1 = -.061313240195;

x = linspace(a,b,ni);

f = (exp(x) - 1)./x;

f((n/2)+1) = 1;

i = 1;

To = 0;

Toi = zeros(1,ni);

while i <= ni   if i == 1 || i == ni        Toi(i) = 0.5*f(i); else Toi(i) = f(i); end To = To + (Toi(i)); i = i+1; end

To = h*To; CTk1 = To + a1*h^2 Enk1 = abs(I - CTk1)

end

b.) Compute In using CTk(n) for k = 2
Using equations 6.2, 6.3 and 6.5 we compute CT2(n)


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



(6.6)
 * $$\displaystyle CT_2(n) = CT_{1}(n) + a^0_2h^{4} + O(h^{6})$$
 * 
 * }
 * }


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




 * $$\displaystyle a^0_2 = d_2 \left[ f^{(3)}(1) - f^{(3)}(-1) \right] = \frac{1}{720}\left[0.563436343081 - 0.113928941256 \right] = 0.000624315835 $$


 * }
 * }

The MatLab code below was used for different values of n to generate the following table:

function [CTk2,Enk2] = CorTrapk2(a,b,n) %Corrected Trapezoidal Rule for k = 2 %  f(x) = (e^x - 1)/x

h = (b - a)/n; ni = n+1; I = 2.11450175075; a2 = -.000624315835;

CTk2 = CorTrapk1(a,b,n) + a2*h^4

Enk2 = I - CTk2

end

c.) Compute In using CTk(n) for k = 3
Using equations 6.2, 6.3 and 6.6 we compute CT3(n)


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



(6.7)
 * $$\displaystyle CT_3(n) = CT_{2}(n) + a^0_3h^{6} + O(h^{8})$$
 * 
 * }
 * }


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




 * $$\displaystyle a^0_3 = d_3 \left[ f^{(3)}(1) - f^{(3)}(-1) \right] = \frac{-1}{30240}\left[0.395599547802 - 0.071302178109 \right] = -0.000010724119 $$


 * }
 * }

The MatLab code below was used for different values of n to generate the following table:

function [CTk3,Enk3] = CorTrapk3(a,b,n) %Corrected Trapezoidal Rule for k = 3 %  f(x) = (e^x - 1)/x

h = (b - a)/n; ni = n+1; I = 2.11450175075; a3 = -0.000010724119;

CTk3 = CorTrapk2(a,b,n) + a3*h^6

Enk3 = I - CTk3 end

This problem was solved by Erle Fields