User:Egm6322.s12.team2.shieldsdraft

= R 13.3 - Relative convergence of power series and continued fraction expansions=

Given
Power series expansion of $$\tan x$$:
 * {| style="width:100%" border="0"

$$  \displaystyle \tan x = \sum_{n=1}^\infty \frac{(-1)^{n-1}2^{2n}(2^{2n}-1)B_{2n}}{(2n)!}x^{2n-1}, x \in ]-\pi/2,\pi/2[ $$     (13.3.1)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

in which $$B_n$$ are the Bernoulli numbers:


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

$$  \displaystyle \begin{align} B_1 &= -\frac{1}{2}, B_{2n+1} = 0, n = 1,2,\dots\\ B_0 &= 1, B_2 = \frac{1}{6}, B_4 = -\frac{1}{30}, B_6 = \frac{1}{42}, B_8 = -\frac{1}{30}, \dots \end{align} $$     (13.3.2)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

Continued fraction expansion of $$\tan x$$:
 * {| style="width:100%" border="0"

$$  \displaystyle \tan x = \frac{x}{1-}\frac{x^2}{3-}\frac{x^2}{5-}\frac{x^2}{7-}\frac{x^2}{\ddots} $$     (13.3.3)
 * style="width:95%" |
 * style="width:95%" |
 * 
 * }

Find
Take $$x=\pi/4$$ and compare the term by term convergence of the power series (Eq. 13.3.1) and the continued fraction (Eq. 13.3.3). Provide a plot to visualize the convergence.

Solution
The power series expansion of a function is a standard approximation technique although it does not necessarily show the fastest convergence. The expression for the expansion of $$\tan x$$ is given in Eqn 13.3.1 and is seen to be a function of the Bernoulli numbers. These values are provided in Eq. 13.3.2 and can also be found on Wolfram Alpha. The term-by-term expansion of the function can be created in Matlab very easily by looping over the number of desired terms and summing the values generated by Eq. 13.3.1. This can be seen in the Matlab script provided below.

Creating the continued fraction expansion of $$\tan x$$ is slightly more complicated as it involves a new loop for a given number of terms. Thus, in the Matlab script provided below, the j index corresponds to the desired number of terms and the i index computes the necessary terms for that expansion. It is also necessary to provide an if statement to distinguish between the first term of Eq. 13.3.3, in which the numerator is $$x$$ instead of $$x^2$$.

The convergence for $$x = \pi/4$$ is shown below in the left figure. It can be seen that both techniques have the same initial value $$\tan x = x = \pi/4$$, but the continued fraction expansion converges more rapidly than the power series expansion. The second term of the continued fraction expansion is within the 5\% bounds of the exact solution while the power series is not quite as accurate. Within 4 terms, both solutions are quite accurate.

A potential explanation for the rapid convergence of both methods in the problem is the simple nature of the x-value, as $$\tan(pi/4)=1$$. To investigate this, a different x-value of $$x=\pi/4 + \sqrt(pi/11)$$ was selected; the squared term on the right hand side is small enough that the value still fits within the bounds of $$x\in ]-\pi/2,\pi/2[$$, but does not have a simple solution for $$\tan x $$. No other parameters in the code need to be changed, and the result is seen in the figure on the right. Again, both methods have the same initial condition. The continued fraction expansion requires only 3 terms to converge within the 5\% bounds and additional terms indicate no discernible difference from the exact solution; however, the power series expansion requires 3 times as many terms to converge to the 5\% bounds and still does not appear to be completely converged after 10 terms. This indicates that the continued fraction expansion is more robust for a wide variety of input conditions.



Matt Shields 18:03,6 April 2012 (UTC)