User:Egm6341.s10.Team2.GV

Hello World

[Team2]

Problem Statement
Pg. 6-5

$$ I = \int_{0}^{1}\frac{\exp^{x}-1}{x}dx $$

Use 3 methods to find In:

1) Taylor Series Expansion, Fn 2) Composite Trapezoidal Rule 3) Composite Simpson Rule

for n=2,4,8 ... until the error is of order $$ 10^{-6} $$

Solution 1
1)Taylor Series Expansion

The goal is to perform the following integration,

$$ I = \int_{0}^{1}\frac{\exp^{x}-1}{x}dx $$

The problem with this is that it is an indefinite integral, which must be rewritten in another way in order to analyze it. The method discussed here will be Taylor Series Expansion or McClaurin Series Expansion. The function can be rewritten as follows:

The Taylor Series Expansion for $$ \exp^{x} $$

$$ \exp^{x}= \sum_{j=0}^{\infty} \frac{x^{j}}{j!} = 1 + \sum_{j=1}^{\infty} \frac{x^{j}}{j!} $$

$$ \exp^{x} - 1 = 1 + \sum_{j=1}^{\infty} \frac{x^{j}}{j!} -1 = \sum_{j=1}^{\infty} \frac{x^{j}}{j!} $$

$$ \frac{exp^{x} - 1}{x} = \sum_{j=1}^{\infty} \frac{x^{j-1}}{j!} = f(x)$$

Using this new definition for the function one can then integrate it directly as follows:

$$I = \int_{0}^{1} \sum_{j=1}^{n} \frac{x^{j-1}}{j!} dx $$

Integrating this for a value of n=2 yields the following:

$$I = \int_{0}^{1} \sum_{j=1}^{n=2} \frac{x^{j-1}}{j!} dx $$

$$I = \int_{0}^{1} \frac{x^{0}}{1!} + \frac{x^{1}}{2!} dx = \left [ x \right ]_{0}^{1} + \left [ \frac{x^{2}}{4} \right ]_{0}^{1} = 1 + \frac{1}{4}=1.25$$

For n=4:

$$I = \int_{0}^{1} \frac{x^{0}}{1!} + \frac{x^{1}}{2!} + \frac{x^{2}}{3!} + \frac{x^{3}}{4!} dx = \left [ x \right ]_{0}^{1} + \left [ \frac{x^{2}}{4} \right ]_{0}^{1} + \left [ \frac{x^{3}}{18} \right ]_{0}^{1} + \left [ \frac{x^{4}}{96} \right ]_{0}^{1} = 1 + \frac{1}{4} + \frac{1}{18} + \frac{1}{96} = 1.3160$$

The percent difference between these two results is calculated as follows:

$$ \left | \frac{new-old}{old} \right | \times 100\% = \left | \frac{1.3160-1.25}{1.25}  \right | \times 100\% = 4.48\% $$

The following are the results for other values of n until the error is reduced to the power of $$10^{-16} $$

Matlab Code used to generate the values for the table:

function I =taylor(n) i=1; Itot=0; It=0; while i<=n if i==1 Itot=1; else It=1/(factorial(i)*i); end Itot=Itot+It; i=i+1; end I=Itot;

Solution 2
2)Composite Trapezoidal Rule The formula used to analyze the integral for a function using the composite trapezoidal rule is as follows:

$$ \int_{a}^{b}F(x)dx = (b-a) \frac{f(x_{0})+2\sum_{i=1}^{n-1}f(x_{i})+f(x_{n})}{2n} $$

It is also necessary to state the following, using L'Hopitals Rule

$$ \lim_{0} \frac{\exp^{x}-1}{x} = 1 $$

For n=2 the integration is approximated as follows:

$$ \int_{0}^{1}\frac{\exp^{x}-1}{x}dx $$

$$ x(1)=.5 x(2)=1 $$

$$ I=(1-0) \frac{f(x_{0})+2f(x_{1})+f(x_{2})}{4} = (1) \frac{1+(2\times1.2974)+1.7183}{4} = 1.328 $$

The error is calculated by comparing it to the results obtained using the Taylor Series expansion, as follows:

$$ Error = \frac{\left | Trapezoidal Value - Taylor Value \right |} {\left | Taylor Value \right |} \times 100\%= \frac{\left | 1.328-1.3179 \right |}{1.3179} \times 100\% = .7664\% $$

This table displays the results for similar values:

Matlab Code used to generate the values for the estimates:

function I=ctrapz(n) i=0; Itot=0; It=0; It2=0; h=0; while i<=n if i==0 Itot1=1; else if i<n h=1/n; It(i)=2*valu(h*i); else It2=valu(1); end end Itot=Itot1+sum(It)+It2; i=i+1; end I=Itot/(2*n);

function F= valu(x); F=(exp(x)-1)/x;

Solution 3
The Composite Simpson's Rule

The rule is defined as follows:

$$ In= (b-a) \frac{f(x_{0}+4\sum_{i=1,3,5..}^{n-1}f(x_{i})+2\sum_{j=2,4,6...}^{n-2}f(x_{j})+f(x_{n})}{3n} $$

Using this definition the following is found:

The Following MATLAB code was used to generate the values:

function I = simpb(a,b,w) q=1; i=a; n=0; Sum=0; c=0; while n<w n=2^q; h=(a+b)/n; while i<=b fx=(exp(i)-1)/(i); if i==a Sum=1; else if i==b Sum=Sum+fx; else if i==(b-h) Sum=Sum+(4*fx); else if rem(c,2)==0 Sum=Sum+(2*fx); else Sum=Sum+(4*fx); end end end end c=c+1; i=i+h; end n    In=Sum*(h/3); I=In; i=a; c=0; q=q+1; Sum=0; end

By Comparing all of the methods one is able to conclude that the most efficient method to numerically integrate was the composite Simpson's rule.