User:EGM6341.s10.Team1.toddmock/HW3

= Problem : Error on Numerical Integrals =

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

Find
Using three numerical integration methods (Taylor series expansion, Simpson's rule, trapezoidal rule) find at what iteration (n) the error approaches an order of 1e-6

Solution
In general there error of a numerical integration is the exact integral minus the numerical integral:


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

$$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle E_n=I-I_n
 * }
 * }

For the Taylor series error is just the integral of the remainder term which is


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

$$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle R_n(x)=e^{\xi }\frac{x^n}{(n+1)!}
 * }
 * }

Then from p.7-1:


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

$$  \displaystyle \int_{0}^{1}[f(x)-f_n(x)]dx=e^{\xi } \int_{0}^{1}\frac{x^n}{(n+1)!}dx $$    (3) Completing the integration gives
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }


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

$$ $$ Choosing $$\xi=0,1$$ then the error is bounded
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle e^{\xi }\frac{1}{(n+1)!(n+1)}
 * }
 * }


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

$$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle \frac{1}{(n+1)!(n+1)} 16-3:
 * {| style="width:100%" border="0" align="left"

$$ $$ where
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle \left | E_n^1 \right |\leq \frac{(b-a)}{12n^2}M_2
 * }
 * }
 * {| style="width:100%" border="0" align="left"

$$ $$ for
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle M_2 = max | f^{(2)} (\xi )|
 * }
 * }
 * {| style="width:100%" border="0" align="left"

$$ $$ Here
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle \xi \varepsilon [a,b]
 * }
 * }
 * {| style="width:100%" border="0" align="left"

$$ $$ the max occurs at $$\xi = 1$$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle f^{(2)}=\frac{(x^2-2x+2)e^x-2}{x^3}
 * }
 * }

Finally for the Simpson's rule:
 * {| style="width:100%" border="0" align="left"

$$ $$ where
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle \left | E_n^2 \right |\leq \frac{(b-a)^5}{2880n^4}M_4
 * }
 * }
 * {| style="width:100%" border="0" align="left"

$$ $$ for
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle M_4 = max | f^{(4)} (\xi )|
 * }
 * }
 * {| style="width:100%" border="0" align="left"

$$ $$ and
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle \xi \varepsilon [a,b]
 * }
 * }
 * {| style="width:100%" border="0" align="left"

$$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle f^{(4)}=\frac{(x^4-4x^3-24x+24)e^x-24}{x^5}
 * }
 * }

Using these three MATLAB codes:

the results below were obtained:

$$ \begin{array}{|c||c|c|c|} n & E_n^{Trap} & E_n^{Taylor} & E_n^{Simpson} \\ \hline 1&0.059900000&0.679600000&0.000161300\\ 2&0.007500000&0.151000000&0.000010081\\ 3&0.002200000&0.028300000&0.000001991\\ 4&0.000935260&0.004500000&--\\	5&0.000478850&0.000629230&--\\	6&0.000277110&0.000077049&--\\	7&0.000174510&0.000008427&--\\	8&0.000116910&--&--\\		9&0.000082108&--&--\\		10&0.000059857&--&--\\		11&0.000044971&--&--\\	12&0.000034639&--&--\\		13&0.000027245&--&--\\	14&0.000021814&--&--\\		15&0.000017735&--&--\\		16&0.000014613&--&--\\		17&0.000012183&--&--\\		18&0.000010264&--&--\\		19&0.000008727&--&--\\ \hline \end{array} $$

From this table it can be seen that the Simpson's rule for numerical integration seems to be the best in that it gives an accurate answer in minimal spatial steps

= Problem :Error on Numerical Integrals Cont'd =

Find
Plot the step size (h) against the integration error in such a way as to determine a power relation between the two

Solution
Plotting the Log of the step size (h) against the log of the error is most appropriate here because the plot will be a straight line. From the fit equation:


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

$$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle Log(E_n)=a[Log(h)]+b


 * }
 * }

it can then be shown that the slope (a) becomes the power term on h.


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

$$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle 10^{Log(E_n)}=10^{a(log(h))+b}


 * }
 * }


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

$$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle\Rightarrow E_n=10^bh^a

Thus it can be seen in the plots that for the Trapezoidal rule
 * }
 * }
 * {| style="width:100%" border="0" align="left"

$$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle E_n\propto h^3


 * }
 * }

and for the Simpson's rule


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

$$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle E_n\propto h^4


 * }
 * }



$$ \begin{array}{|c||c|c|} n & Log(h) & Log(E_n) \\ \hline 1&0.000000&1.2228864\\ 2&0.301030&2.1259764\\ 3&0.477121&2.6542501\\ 4&0.602060&3.0290663\\ 5&0.698970&3.3197964\\ 6&0.778151&3.5573401\\ 7&0.845098&3.7581805\\ 8&0.903090&3.9321563\\ 9&0.954243&4.0856139\\ 10&1.000000&4.2228864\\ \hline \end{array} $$



$$ \begin{array}{|c||c|c|} n & Log(h) & Log(E_n) \\ \hline 1&0.00000&3.792372685\\ 2&0.30103&4.996492668\\ 3&0.47712&5.700857704\\ 4&0.60206&6.200612651\\ 5&0.69897&6.588252703\\ 6&0.77815&6.904977687\\ 7&0.84510&7.172764845\\ 8&0.90309&7.404732633\\ 9&0.95424&7.609342723\\ 10&1.00000&7.792372685\\ \hline \end{array} $$