User:Egm6322.s12.TEAM1.KIM/HW3

Problem 3: Pose Question to be solved
 Solved without assistance 

Given
Power series of tan x: $$\displaystyle x \in ]-\pi /2,\pi/2 [$$ $$\displaystyle tan x = x + \frac{1}{3}x^3 + \frac{2}{15}x^5 + ... + \frac{(-1)^{n-1}2^{2n}(2^{2n}-1)B_{2n}}{(2n)!}x^{2n-1} + ...$$ Continued fraction of tan x: $$\displaystyle tan x = \frac{x}{\displaystyle 1 -\frac{x^2}{\displaystyle 3 -\frac{x^2}{\displaystyle 5 -\frac{x^2}{\displaystyle 7 -\frac{x^2}{\ddots}}}}}$$

Find
Take $$x = \pi / 4$$ and compare the term -by-term convergence of the power series (2) p.48-25b and the continued fraction (1). Provide a plot to visualize the convergence.

Solution
the exact solution of $$\displaystyle tan\left(\frac{\pi}{4}\right )$$ is 1.0 x = $$\frac{\pi}{4}$$ For power series, when n = 1 $$\displaystyle tanx = x = \frac{\pi}{4}=0.7853$$ When n = 2, $$\displaystyle tanx = x + \frac{1}{3}x^3= 0.9467$$ When n = 3, $$\displaystyle tanx = x + \frac{1}{3}x^3 + \frac{2}{15}x^5 = 0.9865$$ When n = 4, $$\displaystyle tanx = x + \frac{1}{3}x^3 + \frac{2}{15}x^5 + \frac{17}{315}x^7 = 0.99649$$ When n =5, $$\displaystyle tanx = x + \frac{1}{3}x^3 + \frac{2}{15}x^5 + \frac{17}{315}x^7 + \frac{62}{2835}x^9 = 0.9989$$ For continued fraction method, n = 1 $$\displaystyle tan x = \frac{x}{\displaystyle 1} = \frac{\pi}{4} = 0.7853 $$ When n = 2, $$\displaystyle tan x = \frac{x}{\displaystyle 1 -{x^2}}= 2.0498$$ When n =3, $$\displaystyle tan x = \frac{x}{\displaystyle 1 -\frac{x^2}{\displaystyle 3 -{x^2}}} = 1.059685$$ When n =4, $$\displaystyle tan x = \frac{x}{\displaystyle 1 -\frac{x^2}{\displaystyle 3 -\frac{x^2}{\displaystyle 5 -{x^2}}}} = 1.00144$$ When n = 5, $$\displaystyle tan x = \frac{x}{\displaystyle 1 -\frac{x^2}{\displaystyle 3 -\frac{x^2}{\displaystyle 5 -\frac{x^2}{\displaystyle 7 -{x^2}}}}}= 1.000018$$ These results show that if n goes to lager, the convergence speed of continued fraction method will be faster than power series.

Problem 7: Legendre homogeneous solution
 Solved without assistance 

Given
$$\displaystyle A_n = \frac{2n+1}{2} \int_{-1}^{1} f(\mu)P_n(\mu)d\mu $$ $$\displaystyle f(\mu) = T_0 \sinh(1-\mu^2) $$

Find
Compute the first 3 non-zero coefficients using Gauss-Legendre quadrature to within 5% error.

Solution
$$\displaystyle \begin{align} &P_0\left(\mu\right)=1 ,\\ &P_2\left(\mu\right)=\frac{1}{2}\left(3\mu^2-1\right) ,\\ &P_4\left(\mu\right)=\frac{1}{8}\left(35\mu^4-30\mu^2+3\right) ,\\ &P_6\left(\mu\right)=\frac{1}{16}\left(231\mu^6-315\mu^4+105\mu^2-5\right) .\\ \end{align} $$

Using the above values and plugging into eq 7.2,  $$\displaystyle A_n = \frac {2(n) + 1}{2}\int_{-1}^{1}T_0sinh(1-\mu^2)P_n(\mu)d\mu$$ $$\displaystyle A_0 = \frac {2(0) + 1}{2}\int_{-1}^{1}T_0sinh(1-\mu^2)P_0(\mu)d\mu = \frac {1}{2} * 1.492T_0 = 0.746T_0$$ $$\displaystyle A_2 = \frac {2(2) + 1}{2}\int_{-1}^{1}T_0sinh(1-\mu^2)P_2(\mu)d\mu = -0.7997T_0$$ $$\displaystyle A_4 = \frac {2(4) + 1}{2}\int_{-1}^{1}T_0sinh(1-\mu^2)P_4(\mu)d\mu = 0.066713T_0$$

Using Matlab, I compute the coefficient.

Problem 1: Computing non-zero coefficients in the Legendre Series
 Solved without assistance 

Given: Expectation of 1% accuracy
Reference: Problem 7, Report 10 $$\displaystyle f(\mu) = T_0 \sinh(1-\mu^2) $$ $$\displaystyle A_n = \frac {2(n) + 1}{2}\int_{-1}^{1}T_0sinh(1-\mu^2)P_n(\mu)d\mu$$

Find
A) Compute the first non-zero coefficient in the Legendre Series with increasing number of integration points until convergence to within 1% accuracy is achieved. B) Provide the expression for the exact solution if possible (use WA) C) Plot the integration error versus the number of integration points.

part1
According to the homework 10.7, the coefficient $$\displaystyle A_n$$is non-zero term when n = even number. Thus A0, A2, A4, A6.... will be non-zero term. The first non-zero term coefficient is $$\displaystyle A_0 = 0.7459T_0$$ $$I_n(f) = \sum_{j=1}^n w_jf(x_j)\approx A_j = \frac{2j+1}{2} \int_{-1}^1 P_j(x)T_0 \sinh{(1 - x^2)}dx $$ When j =0, the above equation is following that $$\displaystyle A_0 = 0.7459T_0 = I_n(f) = \sum_{j=1}^n w_jf(x_j)$$ Where $$\displaystyle x_j$$ is the roots of polynomials When integration point is 1, $$\displaystyle A_0 = 1/2*\sum_{j=1}^1 w_1f(x_1)=1/2*(1.175*2)=1.175T_0$$ When integration point is 2, $$\displaystyle A_0 = 1/2*(w_1*f(x_1)+w_2*f(x_2))=0.7172T_0$$ When integration point is 3, $$\displaystyle A_0 = 1/2*(w_1*f(x_1)+w_2*f(x_2)+w_3*f(x_3))=0.7505T_0$$ When integration point is 4, $$\displaystyle A_0 = 1/2*(w_1*f(x_1)+w_2*f(x_2)+w_3*f(x_3)+w_4*f(x_4))=0.7459T_0$$ These results show that n=4, the accuracy is almost 0%. Now see the lecture note 45-7. Equation in lecture note 45-7 is that $$E_n(f) = \frac{2^{2n+1}(n!)^4}{(2n+1)[(2n)!]^2} \frac{f^{2n}(\eta)}{(2n)!}, \eta \in [-1,1]$$ $$I(f) = I_n(f) + E_n(f)$$ $$I(f) - I_n(f) = E_n(f)$$ When n goes to oo, E_n(f) will be zero. Assume the exact A_0 is 0.7459.For the accuracy, 0.007459 will be allowed in $$\displaystyle I(f)-I_n(f)$$ $$\displaystyle E_n(f)= 0.007459$$ using the matlab, the results showed that

Thus the answer is n = 4.

part2
By using Wlofram Alpha, exact expression should be

The exact solution is 0.74601369.....(this value was estimated by n=5)

part3
The above table is from wikipedia. $$E_n(f) = \frac{2^{2n+1}(n!)^4}{(2n+1)[(2n)!]^2} \frac{f^{2n}(\eta)}{(2n)!}, \eta \in [-1,1]$$ When $$\displaystyle \eta $$ is 0.9, 9, -0.9,

Problem 8: Verification
 Solved without assistance 

Find
Verify equation 8.1 and show that for $$ i=1,...,n \ $$ and thus

Part1
$$\ell_j(x_i) = \prod_{m=0,\, m\neq j}^{k} \frac{x_i-x_m}{x_j-x_m} $$ From above equation, when $$m = j$$, the product skips And if $$i = j$$ the above equation's all terms are $$\frac{x_j-x_m}{x_j-x_m} = 1$$ except where $$x_j = x_m$$ if $$i \neq j$$ then since $$m \neq j$$ doesn't preclude it, one term in the product will be for $$m=i$$, $$\frac{x_i-x_i}{x_j-x_i} = 0$$ Thus, $$\ell_j(x_i) = \delta_{ji} = \begin{cases} 1, & \text{if } j=i  \\ 0, & \text{if } j \ne i \end{cases} $$ Where $$\displaystyle \delta_{ji}$$ is that The value is 1 if they are equal $$ \delta_{1 \, 1} = 1 $$

And 0 otherwise. $$\delta_{1 \, 2} = 0. $$

Part2
$$\displaystyle p^h(x) = \sum_{j=1}^n p(x_j)\ell_j(x) $$ $$\displaystyle d(x)=p(x) - p^h(x) = p(x) - \sum_{j=1}^n p(x_j)\ell_j(x) $$ $$\displaystyle d(x_i)=p(x_i) - p^h(x_i) = p(x_i) - \sum_{j=1}^n p(x_j)\ell_j(x_i) $$ $$\displaystyle d(x_i)=p(x_i) - \sum_{j=1}^n p(x_j)\ell_j(x_i) = p(x_i)-[p(x_1)\ell_1(x_i) + p(x_2)\ell_2(x_i)+ p(x_3)\ell_3(x_i)+ .......+ p(x_n)\ell_n(x_i)] $$ When j = i, $$\displaystyle \ell_j(x_i) = \delta_{ji} = 1$$ $$\displaystyle p(x_i)\ell_i(x_i) = p(x_i)$$ The other terms are always zero. Hence, $$\displaystyle d(x_i) = p(x_i) - p(x_i) = 0$$

Problem 5: Integrate and Find Number of Integration Points
 Solved without assistance 

Find: A & B below
A) Integrate Equation 5.1 analytically (not numerically) exactly over $$ [-1,1] \ $$ B) Determine the least nmber of integration points to integrate Eq5.1 exactly with the GL Quadrature. Carry out the integration and compare to the exact result.

part A
$$\displaystyle p(x) = \frac{x^7}{8} + \frac{x^6}{7} + \frac{x^2}{3} + 5$$ $$\displaystyle \int_{x=-1}^{x=1} p(x)dx = \int_{x=-1}^{x=1} (\frac{x^7}{8} + \frac{x^6}{7} + \frac{x^3}{3} + 5)dx $$ $$\displaystyle = [\frac {x^8}{8^2} + \frac{x^7}{7^2} + \frac{x^3}{3^2} +5x]_{-1}^{1} = \frac{492}{4} $$

part B
p(x) is 7 order equation. If n = 4, $$\displaystyle \int_{-1}^{1} f[x]dx = w_1f[x_1] + w_2f[x_2] + w_3f[x_3]+w_4f[x_4] $$ Where $$\displaystyle f_1[x] =1,f_2[x] =x,f_3[x]=x^2, ...... ,f_8[x] = x^7$$ $$\displaystyle \int_{-1}^{1} f_1[x]dx = w_1f_1[x_1] + w_2f_1[x_2] + w_3f_1[x_3]+w_4f_1[x_4] $$ $$\displaystyle \int_{-1}^{1} f_2[x]dx = w_1f_2[x_1] + w_2f_2[x_2] + w_3f_2[x_3]+w_4f_2[x_4] $$ $$\displaystyle \int_{-1}^{1} f_3[x]dx = w_1f_3[x_1] + w_2f_3[x_2] + w_3f_3[x_3]+w_4f_3[x_4] $$ $$\displaystyle \int_{-1}^{1} f_4[x]dx = w_1f_4[x_1] + w_2f_4[x_2] + w_3f_4[x_3]+w_4f_4[x_4] $$ $$\displaystyle \int_{-1}^{1} f_5[x]dx = w_1f_5[x_1] + w_2f_5[x_2] + w_3f_5[x_3]+w_4f_5[x_4] $$ $$\displaystyle \int_{-1}^{1} f_6[x]dx = w_1f_6[x_1] + w_2f_6[x_2] + w_3f_6[x_3]+w_4f_6[x_4] $$ $$\displaystyle \int_{-1}^{1} f_7[x]dx = w_1f_7[x_1] + w_2f_7[x_2] + w_3f_7[x_3]+w_4f_7[x_4] $$ $$\displaystyle \int_{-1}^{1} f_8[x]dx = w_1f_8[x_1] + w_2f_8[x_2] + w_3f_8[x_3]+w_4f_8[x_4] $$ From the above equations, $$\displaystyle w_1 + w_2 + w_3 + w_4= 2$$

$$\displaystyle w_1x_1 + w_2x_2 + w_3x_3 + w_4x_4= 0$$

$$\displaystyle w_1x_1^2 + w_2x_2^2 + w_3x_3^2 + w_4x_4^2= \frac{2}{3}$$

$$\displaystyle w_1x_1^3 + w_2x_2^3 + w_3x_3^3 + w_4x_4^3= 0$$

$$\displaystyle w_1x_1^4 + w_2x_2^4 + w_3x_3^4 + w_4x_4^4= \frac{2}{5}$$

$$\displaystyle w_1x_1^5 + w_2x_2^5 + w_3x_3^5 + w_4x_4^5= 0$$

$$\displaystyle w_1x_1^6 + w_2x_2^6 + w_3x_3^6 + w_4x_4^6= \frac{2}{7}$$

$$\displaystyle w_1x_1^7 + w_2x_2^7 + w_3x_3^7 + w_4x_4^7= 0$$

As a result of the above equations, the solution is that $$\displaystyle x_1 = -0.86113$$ $$\displaystyle x_2 = -0.33998$$ $$\displaystyle x_3 = 0.33998$$ $$\displaystyle x_4 = 0.86113$$ $$\displaystyle w_1 = 0.34785$$ $$\displaystyle w_2 = 0.65214$$ $$\displaystyle w_3 = 0.65214$$ $$\displaystyle w_4 = 0.34785$$

These results show that $$\displaystyle \int_{x=-1}^{x=1} p(x)dx = \sum_{j=1}^{n}w_jp(x_j) $$ Actually, $$\displaystyle \int_{x=-1}^{x=1} p(x)dx = \frac{492}{49} = 10.0408 $$ However, using the above values, $$\displaystyle \sum_{j=1}^{n}w_jp(x_j) = 10.2630$$ I think it is round-off error and truncation error.