You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using ``ContinuedFraction.from_elements()`` can be very useful when trying to approximate irrational numbers with (finite) continued fractions. We know, for example, that the square root :math:`sqrt(n)` of any non-square (positive) integer :math:`n` is irrational. This can be proved quite easily by writing :math:`n = a^2 + r`, for integers :math:`a, r > 0`, from which we have:
96
+
97
+
.. math::
98
+
:nowrap:
99
+
100
+
\begin{alignat*}{1}
101
+
& r &&= n - a^2 = \left(\sqrt{n} + a\right)\left(\sqrt{n} - a\right) \\
102
+
& \sqrt{n} &&= a + \frac{r}{a + \sqrt{n}}
103
+
\end{alignat*}
104
+
105
+
Expanding the expression for :math:`\sqrt{n}` recursively we have the following infinite periodic continued fraction representation for :math:`\sqrt{n}`:
Then we can iteratively construct more accurate ``ContinuedFraction`` approximations of :math:`\sqrt{n}` by taking more complete sequences of the elements of the completed continued fraction representation:
With the first :math:`10` elements of the complete sequence of elements of the continued fraction representation of :math:`\sqrt{2}` we have obtained an approximation that is accurate to :math:`6` decimal places. We'd ideally like to have as few elements as possible in our ``ContinuedFraction`` approximation of :math:`\sqrt{2}` for a desired level of accuracy, but this partly depends on how fast the partial, finite continued fractions represented by the chosen sequences of elements in our approximations are converging to the true value of :math:`\sqrt{2}` - these partial, finite continued fractions in a continued fraction representation are called convergents, and will be discussed in more detail later on.
0 commit comments