$\pi$ is an irrational number. MATLAB shows it equal to 355/113 in fractional format. Is there no better fractional representation than 355/113 within the limits of the finite precision the computers use? How is the value arrived at?
-
1It is a surprisingly good approximation - error less than $3\cdot10^{-7}$ – almagest Apr 27 '16 at 15:27
-
2It comes from the simple continued fraction representation of pi – Ben Grossmann Apr 27 '16 at 15:29
-
I think you'd have to find a detailed description of what "format rat" is supposed to do in order to get a compelling answer to this question. As has already been mentioned, 355/113 is one of the continued fraction approximants of pi, but it is not so obvious why format rat picks that one in particular. (As it happens, that one is unusually good for its size because the next continued fraction convergent is 292...but that doesn't tell you why 355/113 is actually adequate.) – Ian Apr 27 '16 at 15:32
-
Some other rational expressions that approximate pi really well can be found here: https://en.wikipedia.org/wiki/Mil%C3%BC – imranfat Apr 27 '16 at 15:32
-
1Does MATLAB $\pi$ really handle to be EQUAL to $\frac{355}{113}$ ? – Peter Apr 27 '16 at 15:37
-
If I remember right, this approximation is known since over $1,000$ years. – Peter Apr 27 '16 at 15:39
-
Of course, there are better approximations, but this approximation should be the best in relation to its simplicity. The reason is that the continued fraction has a large number in an early position. – Peter Apr 27 '16 at 15:43
-
2@Peter: the formula isn't extremely useful as it requires you to remember six digits to get... six exact figures. – Apr 27 '16 at 15:47
-
But only three distinct digits :) And they are all odd :) – Peter Apr 27 '16 at 15:49
-
$\frac{22}{7}$ is often used, although it is a much worse approximation. Curious fact : There was a law in the USA, demanding $\pi$ to be $4$, no joke! Easy enough to remember :) – Peter Apr 27 '16 at 15:51
-
@peter: in addition, those three digits form an arithmetic progression ($135$), their pairwise sums in the fraction form another progression ($468$), and they are the ones appearing in a famous approximation of a famous number ;-) – Apr 27 '16 at 16:07
-
@Peter If you display pi in format rat, it prints 355/113. You don't have pi == 355/113 in Matlab, though. – Ian Apr 27 '16 at 16:17
2 Answers
Matlab presumably showcases this close approximation somewhere. But it never ever trades that value for the true $\pi$.
To get to it, truncate $\pi$ to the nearest integer, take the fractional part and invert it. Repeat. The integers that you see are
$$3,7,15,1\cdots$$
So reverting the process, approximations of $\pi$ are
$$3,3+\frac17=\frac{22}7,3+\frac1{7+\frac1{15}}=\frac{333}{106},3+\frac1{7+\frac1{15+\frac11}}=\frac{355}{113},\cdots$$
Next are $\dfrac{103993}{33102}$, $\dfrac{104348}{33215}$ and you can continue.
The irreducible fraction $\frac{355}{113}$ of MATLAB gives certainly a good approximation, as @almagest comment. One could argue that the irreducible $\frac{208341}{66317}$ ($\frac{22}{17}+\frac{37}{47}+\frac{88}{83}$ indeed) is another rational approximation with an accuracy of nine decimal digits of exactness. However it is true that $\frac{355}{113}$ is easier to manipulate that $\frac{208341}{66317}$ which could be the MATLAB's purpose.
- 29,594
-
Thanks to all who have commented and answered my question and gave very useful and unknown information to me. But my basic question remains this. Irrespective of what format you use to display the numbers MATLAB uses the same value for a number like pi or any other number like sqrt(2). So format rat is just an approximation to a fractional number what MATLAB must be using as value of a number. How is MATLAB arriving at fractional approximation? Why pi 355/113 or why sqrt(2) is 1393/985? Are there no better representable fractions in MATLAB for these numbers? What algorithm does it use? – Seetha Rama Raju Sanapala Apr 27 '16 at 17:54
-
1Matlab uses a default tolerance of $10^{-6}$ for
rat, so 355/113 is within that tolerance. You can lower the tolerance to get better approximations. Read here for more details. – David Apr 27 '16 at 22:42