User:Egm6341.spring-11.5.D/HW2

= Problem 1 - Taylor Series = = Problem 2 -Taylor Series =

Problem statement
Construct the first 10 Taylor series expansions of: $$ f(x)=sin x, \ x \in [0,\pi] $$

Solution
 Solved my self using Mathematica 7 and the following commands: Table[Series[Sin[x], {x, 3*Pi/8, n}], {n, 0, 10}]; MatrixForm[Normal[%]]

$$ \left( \begin{array}{c} \cos \left(\frac{\pi }{8}\right) \\ \left(x-\frac{3 \pi }{8}\right) \sin \left(\frac{\pi }{8}\right)+\cos \left(\frac{\pi }{8}\right) \\ \left(x-\frac{3 \pi }{8}\right) \sin \left(\frac{\pi }{8}\right)-\frac{1}{2} \left(x-\frac{3 \pi }{8}\right)^2 \cos \left(\frac{\pi }{8}\right)+\cos \left(\frac{\pi }{8}\right) \\ -\frac{1}{6} \left(x-\frac{3 \pi }{8}\right)^3 \sin \left(\frac{\pi }{8}\right)+\left(x-\frac{3 \pi }{8}\right) \sin \left(\frac{\pi }{8}\right)-\frac{1}{2} \left(x-\frac{3 \pi }{8}\right)^2 \cos \left(\frac{\pi }{8}\right)+\cos \left(\frac{\pi }{8}\right) \\ -\frac{1}{6} \left(x-\frac{3 \pi }{8}\right)^3 \sin \left(\frac{\pi }{8}\right)+\left(x-\frac{3 \pi }{8}\right) \sin \left(\frac{\pi }{8}\right)+\frac{1}{24} \left(x-\frac{3 \pi }{8}\right)^4 \cos \left(\frac{\pi }{8}\right)-\frac{1}{2} \left(x-\frac{3 \pi }{8}\right)^2 \cos \left(\frac{\pi }{8}\right)+\cos \left(\frac{\pi }{8}\right) \\ \frac{1}{120} \left(x-\frac{3 \pi }{8}\right)^5 \sin \left(\frac{\pi }{8}\right)-\frac{1}{6} \left(x-\frac{3 \pi }{8}\right)^3 \sin \left(\frac{\pi }{8}\right)+\left(x-\frac{3 \pi }{8}\right) \sin \left(\frac{\pi }{8}\right)+\frac{1}{24} \left(x-\frac{3 \pi }{8}\right)^4 \cos \left(\frac{\pi }{8}\right)-\frac{1}{2} \left(x-\frac{3 \pi }{8}\right)^2 \cos \left(\frac{\pi }{8}\right)+\cos \left(\frac{\pi }{8}\right) \\ \frac{1}{120} \left(x-\frac{3 \pi }{8}\right)^5 \sin \left(\frac{\pi }{8}\right)-\frac{1}{6} \left(x-\frac{3 \pi }{8}\right)^3 \sin \left(\frac{\pi }{8}\right)+\left(x-\frac{3 \pi }{8}\right) \sin \left(\frac{\pi }{8}\right)-\frac{1}{720} \left(x-\frac{3 \pi }{8}\right)^6 \cos \left(\frac{\pi }{8}\right)+\frac{1}{24} \left(x-\frac{3 \pi }{8}\right)^4 \cos \left(\frac{\pi }{8}\right)-\frac{1}{2} \left(x-\frac{3 \pi }{8}\right)^2 \cos \left(\frac{\pi }{8}\right)+\cos \left(\frac{\pi }{8}\right) \\ -\frac{\left(x-\frac{3 \pi }{8}\right)^7 \sin \left(\frac{\pi }{8}\right)}{5040}+\frac{1}{120} \left(x-\frac{3 \pi }{8}\right)^5 \sin \left(\frac{\pi }{8}\right)-\frac{1}{6} \left(x-\frac{3 \pi }{8}\right)^3 \sin \left(\frac{\pi }{8}\right)+\left(x-\frac{3 \pi }{8}\right) \sin \left(\frac{\pi }{8}\right)-\frac{1}{720} \left(x-\frac{3 \pi }{8}\right)^6 \cos \left(\frac{\pi }{8}\right)+\frac{1}{24} \left(x-\frac{3 \pi }{8}\right)^4 \cos \left(\frac{\pi }{8}\right)-\frac{1}{2} \left(x-\frac{3 \pi }{8}\right)^2 \cos \left(\frac{\pi }{8}\right)+\cos \left(\frac{\pi }{8}\right) \\ -\frac{\left(x-\frac{3 \pi }{8}\right)^7 \sin \left(\frac{\pi }{8}\right)}{5040}+\frac{1}{120} \left(x-\frac{3 \pi }{8}\right)^5 \sin \left(\frac{\pi }{8}\right)-\frac{1}{6} \left(x-\frac{3 \pi }{8}\right)^3 \sin \left(\frac{\pi }{8}\right)+\left(x-\frac{3 \pi }{8}\right) \sin \left(\frac{\pi }{8}\right)+\frac{\left(x-\frac{3 \pi }{8}\right)^8 \cos \left(\frac{\pi }{8}\right)}{40320}-\frac{1}{720} \left(x-\frac{3 \pi }{8}\right)^6 \cos \left(\frac{\pi }{8}\right)+\frac{1}{24} \left(x-\frac{3 \pi }{8}\right)^4 \cos \left(\frac{\pi }{8}\right)-\frac{1}{2} \left(x-\frac{3 \pi }{8}\right)^2 \cos \left(\frac{\pi }{8}\right)+\cos \left(\frac{\pi }{8}\right) \\ \frac{\left(x-\frac{3 \pi }{8}\right)^9 \sin \left(\frac{\pi }{8}\right)}{362880}-\frac{\left(x-\frac{3 \pi }{8}\right)^7 \sin \left(\frac{\pi }{8}\right)}{5040}+\frac{1}{120} \left(x-\frac{3 \pi }{8}\right)^5 \sin \left(\frac{\pi }{8}\right)-\frac{1}{6} \left(x-\frac{3 \pi }{8}\right)^3 \sin \left(\frac{\pi }{8}\right)+\left(x-\frac{3 \pi }{8}\right) \sin \left(\frac{\pi }{8}\right)+\frac{\left(x-\frac{3 \pi }{8}\right)^8 \cos \left(\frac{\pi }{8}\right)}{40320}-\frac{1}{720} \left(x-\frac{3 \pi }{8}\right)^6 \cos \left(\frac{\pi }{8}\right)+\frac{1}{24} \left(x-\frac{3 \pi }{8}\right)^4 \cos \left(\frac{\pi }{8}\right)-\frac{1}{2} \left(x-\frac{3 \pi }{8}\right)^2 \cos \left(\frac{\pi }{8}\right)+\cos \left(\frac{\pi }{8}\right) \\ \frac{\left(x-\frac{3 \pi }{8}\right)^9 \sin \left(\frac{\pi }{8}\right)}{362880}-\frac{\left(x-\frac{3 \pi }{8}\right)^7 \sin \left(\frac{\pi }{8}\right)}{5040}+\frac{1}{120} \left(x-\frac{3 \pi }{8}\right)^5 \sin \left(\frac{\pi }{8}\right)-\frac{1}{6} \left(x-\frac{3 \pi }{8}\right)^3 \sin \left(\frac{\pi }{8}\right)+\left(x-\frac{3 \pi }{8}\right) \sin \left(\frac{\pi }{8}\right)-\frac{\left(x-\frac{3 \pi }{8}\right)^{10} \cos \left(\frac{\pi }{8}\right)}{3628800}+\frac{\left(x-\frac{3 \pi }{8}\right)^8 \cos \left(\frac{\pi }{8}\right)}{40320}-\frac{1}{720} \left(x-\frac{3 \pi }{8}\right)^6 \cos \left(\frac{\pi }{8}\right)+\frac{1}{24} \left(x-\frac{3 \pi }{8}\right)^4 \cos \left(\frac{\pi }{8}\right)-\frac{1}{2} \left(x-\frac{3 \pi }{8}\right)^2 \cos \left(\frac{\pi }{8}\right)+\cos \left(\frac{\pi }{8}\right) \end{array} \right) /,$$

Residual
$$Max\left|R(x)_{n+1}\right|=\frac{\left(x-x_0\right){}^{n+1} Max\left|f(\zeta )^{n+1}\right|}{(n+1)!}, \zeta \in \left[x_o, x\right],x_0=\frac{3 \pi }{8},x=\frac{3 \pi }{4}$$ When $$n+1$$ is even $$ Max\left|f(\zeta )^{n+1}\right|=1$$ When $$n+1$$ is odd $$ Max\left|f(\zeta )^{n+1}\right|=\frac{1}{\sqrt{2}}$$ $$\therefore$$ When $$n+1$$ is even: $$Max\left|R(x)_{n+1}\right|=\frac{1.1781^{n+1}}{(n+1)!}$$ And When $$n+1$$ is odd: $$Max\left|R(x)_{n+1}\right|=\frac{1.1781^{n+1}}{\sqrt{2}(n+1)!}$$

Plot expansions
Homework 2 Problem 2 Figure 1: First 10 Taylor series expansions of Sin(x), from 0 to 2$$\pi$$

= Problem 3 - = = Problem 4 - = = Problem 5 - = = Problem 6 - = = Problem 7 - = = Problem 8 - =

= Problem 9 - =

= Problem 10 - =

= Problem 11 - = = Problem 12 - =

Function to gernate Lagrange Interpolation funcitons

LagrangeInterp[data_, x_] /; MatrixQ[data] := Flatten[Module[{n = Length[data], xl},{xl = data};Table[Product[(x - xli)/(xlj - xli), {i,Complement[Range[n], {j}]}], {j, n}]]\[Transpose]]

f[x_] := (Exp[x] - 1)/x

Mathematica code to generate evaluation points, data points, Interpolation funcitons,and interpolated functions for n=[1,2,4,8,16]

fn = Simplify[Table[fpts = Table[f[i], {i, -1.001, 1, 2.001/n}, {j, 1}]; xloc = Table[i, {i, -1.001, 1, 2.001/n}, {j, 1}]; LIf = LagrangeInterp[xloc, x]; LIf.fpts, {n, {1, 2, 4, 8, 16}}]]

Resulting Interpolation functions:

$$ \left( \begin{array}{c} 0.542941 x+1.17534 \\ 0.175144 x^2+0.543116 x+1.00002 \\ 0.00858167 \left(x^2-0.403782 x+11.4075\right) \left(x^2+5.46541 x+10.2149\right) \\ 2.8018942259677715*10^{-6} \left(x^2-5.53948 x+34.1119\right) \left(x^2+0.275742 x+21.7425\right) \left(x^2+5.34705 x+21.6285\right) \left(x^2+8.95483 x+22.2488\right) \\ 1.1816155165433884*10^{-8} x^{16}-1.6916601452976465*10^{-10} x^{15}-3.818422555923462*10^{-8} x^{14}-1.5643308870494366*10^{-10} x^{13}+4.784669727087021*10^{-8} x^{12}+1.760781742632389*10^{-9} x^{11}-6.548361852765083*10^{-9} x^{10}+2.74396370514296*10^{-7} x^9+2.7657661121338606*10^{-6} x^8+0.0000248015 x^7+0.000198411 x^6+0.00138889 x^5+0.00833333 x^4+0.0416667 x^3+0.166667 x^2+0.5 x+1. \end{array} \right)

$$

The difference between the integration of the original function and the interpolation funcitons is used to compare their reletive accurcy. The Mathematica code to accomplish this is:

N[Integrate[f[x], {x, -1, 1}]] - Integrate[fn, {x, -1, 1}]

The results are as follows:

$$\left( \begin{array}{c} -0.236179 \\ -0.00230395 \\ -9.742760151087992*10^{-6} \\ -1.1224932094933138*10^{-10} \\ 3.831686079536212*10^{-10} \end{array} \right)$$

= Problem 13 - =