User:Egm6322.s12.TEAM1.HW/HW5

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%. Actually the accuracy condition was satisfied by n = 3. 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 = 3.

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 2: Prove an Alternative formula for the weights of Gauss-Legendre Quadrature
 Solved without assistance 

Find
Prove that Eq2.3 below is valid

Solution:
Recall (2) p.44b-8: $$\displaystyle (1-{{x}^{2}}){{P}_{n}}^{\prime }(x)=-nx{{P}_{n}}(x)+n{{P}_{n-1}}(x)$$ And, RR2 is shown below: $$\displaystyle (n+1){{P}_{n+1}}-(2n+1)x{{P}_{n}}+n{{P}_{n-1}}=0$$ ,which can be transformed like: $$\displaystyle -nx{{P}_{n}}+n{{P}_{n-1}}=(n+1)x{{P}_{n}}-(n+1){{P}_{n+1}}$$ From the two equations above, we can obtain the following equation: $$(n+1)x{{P}_{n}}-(n+1){{P}_{n+1}}=(1-x_{j}^{2}){{{{P}'}}_{n}}({{x}_{j}})$$ When x is selected to be $${{x}_{j}}$$ (the roots of $${{P}_{n}}(x)$$), $$\displaystyle (n+1){{x}_{j}}{{P}_{n}}({{x}_{j}})-(n+1){{P}_{n+1}}({{x}_{j}})=(1-x_{j}^{2}){{{{P}'}}_{n}}({{x}_{j}})$$ where, $${{P}_{n}}({{x}_{j}})=0$$. So, we can get: $$\displaystyle -(n+1){{P}_{n+1}}({{x}_{j}})=(1-x_{j}^{2}){{{{P}'}}_{n}}({{x}_{j}})$$

Problem 3: Plotting a sequence versus an irrational number to observe convergence
 Solved without assistance 

Given
A sequence: the irrational number: $$ n \ $$ a constant $$ \sqrt{2} \ $$ and a limit:

Find
Plot the sequence versus the irrational number: $$ n \ $$ with the constant $$ \sqrt{2} \ $$ to observe the convergence in Eq3.2.

Solution
I ran the iterations through an excel spreadsheet using the Smyrna Algorithm found on class notes 48-7 I ran the algorithm for 30 iterations for my own curiosity. I found that after 21 iterations, the irrational number n converged completely ( to 16 decimal places) with the square root of 2. A plot of the convergence was created from the data in the excel spreadsheet and is shown below along with the raw data form the spreadsheet.



Problem 4: Write a matlab program to compute the convergents for $$\sqrt 2$$
 Solved without assistance 

Given:

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

\displaystyle \sqrt 2=1+\frac{1}{2+\frac{1}{2+\frac{1}{2+\frac{1}{2+\frac{1}{\ddots}}}}} $$
 * 
 * }
 * }
 * {| style="width:100%" border="0" align="left"

\displaystyle C_0:=1 $$
 * 
 * }
 * }
 * {| style="width:100%" border="0" align="left"

\displaystyle C_1:=1+\frac{1}{2}=\frac{3}{2} $$
 * 
 * }
 * }
 * {| style="width:100%" border="0" align="left"

\displaystyle C_2:=1+\frac{1}{2+\frac{1}{2}}=1+\frac{2}{5}=\frac{7}{5} $$
 * 
 * }
 * }
 * {| style="width:100%" border="0" align="left"

\displaystyle C_3:=1+\frac{1}{2+\frac{1}{2+\frac{1}{2}}}=1+\frac{1}{2+\frac{2}{5}}=1+\frac{5}{12}=\frac{17}{12} $$
 * 
 * }
 * }

Find:
Write a matlab program to compute the convergents $$C_i$$for i=0,1,...,10,and plot these convergents together with the line $$\sqrt 2$$to visualize the convergence
 * {| style="width:100%" border="0" align="left"

\displaystyle \lim_{i \to \infty}C_i=\sqrt 2 $$
 * 
 * }
 * }

Solution:
clear

n=10;

f=sqrt(2); f=sym(f); f=char(f); fplot(f,[-2 2],'r','o'); legend('sqrt(2)'); hold on

disp(['C' char(48) '=']) disp(1)

f=1; f=sym(f); f=char(f); fplot(f,[-2 2]);

for x=1:n; s=0; for i=1:x; s=1/(2+s); end s=1+s; s=vpa(s); disp(['C' char(sym(x)) '=']) disp(s) f=s; f=sym(f); f=char(f); fplot(f,[-2 2]); end axis([-2 2 1.39 1.51])

The results are as follows:









From the results above, we can see that with the increasing of fraction terms, the value will be convergent to the actual value: $$\sqrt 2=1.4142135623730950488016887242097$$.

Problem 5: Verify the Last Term for the nth Approximant of Given Equation
 Solved without assistance 

Find
A) Verify the last term for the nth approximant as shown in Eq5.1 B) Use Eq5.1 to find the Legendre Polynomials $$ \left \{ P_1,...,P_6 \right \} \ $$ and compare the results to those in R10.2 p44-6

Solution:
A).Verify the last term for the nth approximant as shown in Eq5.1. When n=2, the second approximant is: $$\displaystyle \frac{-\frac{2(n-1)-1}{2(n-1)}}{\frac{4(n-1)-1}{2(n-1)}x}=\frac{-\frac{2(2-1)-1}{2(2-1)}}{\frac{4(2-1)-1}{2(2-1)}x}=\frac{-\frac{1}{2}}{\frac{3}{2}x}$$ When n=3, the second approximant is: $$\displaystyle \frac{-\frac{2(n-1)-1}{2(n-1)}}{\frac{4(n-1)-1}{2(n-1)}x}=\frac{-\frac{2(3-1)-1}{2(3-1)}}{\frac{4(3-1)-1}{2(3-1)}x}=\frac{-\frac{3}{4}}{\frac{7}{4}x}$$ So, the n-th term is verified by the these beginning terms. B). According to continued fraction,the Legendre polynomial P_n(x) is the denominator of the n-th approximant to the continue fraction. So, the first one is: $$\displaystyle {{P}_{1}}(x)=x$$ Secondly: $$\displaystyle \frac{x+\frac{-1/2}{3x/2}}=\frac{{{a}_{1}}\centerdot 3x/2}{3{{x}^{2}}/2+-1/2}$$ So, $$\displaystyle {{P}_{2}}(x)=3{{x}^{2}}/2+-1/2$$ Thirdly: $$\displaystyle \frac{x+\frac{-1/2}{3x/2+\frac{-3/4}{7x/4}}}=\frac{x+\frac{-7x/8}{21{{x}^{2}}/8-3/4}}=\frac{{{a}_{1}}\left( 21{{x}^{2}}/8-3/4 \right)}{21{{x}^{3}}/8-3x/4-7x/8}=\frac{{{a}_{1}}\left( 21{{x}^{2}}/8-3/4 \right)}{21{{x}^{3}}/8-13x/8}$$ So, $$\displaystyle {{P}_{3}}(x)=21{{x}^{3}}/8-13x/8$$ Fourthly: $$\displaystyle \frac{x+\frac{-1/2}{3x/2+\frac{-3/4}{7x/4+\frac{-5/6}{11x/6}}}}=\frac{{{a}_{1}}(231{{x}^{3}}/48-63x/24)}{(231{{x}^{4}}-203{{x}^{2}}+20)/48}$$ So, $$\displaystyle {{P}_{4}}(x)=(231{{x}^{4}}-203{{x}^{2}}+20)/48$$ Fifthly: $$\displaystyle \frac{x+\frac{-1/2}{3x/2+\frac{-3/4}{7x/4+\frac{-5/6}{11x/6+\frac{-7/8}{15x/8}}}}}=\frac{{{a}_{1}}(1155{{x}^{4}}-924{{x}^{2}}+84)/128}{\left( 1155{{x}^{5}}-1309{{x}^{3}}+282x \right)/128}$$

So, $$\displaystyle {{P}_{5}}(x)=\left( 1155{{x}^{5}}-1309{{x}^{3}}+282x \right)/128$$

Sixthly: $$\displaystyle \frac{x+\frac{-1/2}{3x/2+\frac{-3/4}{7x/4+\frac{-5/6}{11x/6+\frac{-7/8}{15x/8+\frac{-9/10}{19x/10}}}}}}=\frac{{{a}_{1}}\left( 4389{{x}^{5}}-4620{{x}^{3}}+924x \right)/256}{\left( 4389{{x}^{6}}-6083{{x}^{4}}+2046{{x}^{2}}-96 \right)/256}$$

So, $$\displaystyle {{P}_{6}}(x)=\left( 4389{{x}^{6}}-6083{{x}^{4}}+2046{{x}^{2}}-96 \right)/256$$ In total, polynomial obtained by continued fraction is shown below. $$\displaystyle {{P}_{1}}(x)=x$$ $$\displaystyle {{P}_{2}}(x)=3{{x}^{2}}/2+-1/2$$ $$\displaystyle {{P}_{3}}(x)=21{{x}^{3}}/8-13x/8$$ $$\displaystyle {{P}_{4}}(x)=(231{{x}^{4}}-203{{x}^{2}}+20)/48$$ $$\displaystyle {{P}_{5}}(x)=\left( 1155{{x}^{5}}-1309{{x}^{3}}+282x \right)/128$$ $$\displaystyle {{P}_{6}}(x)=\left( 4389{{x}^{6}}-6083{{x}^{4}}+2046{{x}^{2}}-96 \right)/256$$ The Legendre polynomial obtained by RR2: $$ \displaystyle \begin{align} P_1 &= x \\ P_2 &= \frac{1}{2}(3x^2-1) \\ P_3 &= \frac{1}{2}(5x^3-3x) \\ P_4 &= \frac{1}{8}(35x^4-30x^2+3) \\ P_5 &= \frac{1}{8}(63x^5-70x^3+15x) \\ P_6 &= \frac{1}{16}(231x^6-315x^4+105x^2-5) \end{align} $$ Compared with P_n(x) obtained in R10.2 P44b-6, the factor of P_n(x) generated by continued fraction is larger and increased faster. However, the orthogonality of these polynomials won't be changed by the difference of factor. For example,

$$\displaystyle \left\langle {{P}_{2}},{{P}_{3}} \right\rangle =\int\limits_{-1}^{1}{\left( 3{{x}^{2}}/2-1/2 \right)\left( 21{{x}^{3}}/8-13x/8 \right)dx}=0$$

=Contributing Members & Referenced Lecture=

=Table of Contributions=