How to get the best approximate fraction for a real number in mathematics

If I want to get the best approximate fraction / rationality for a given real number and a specific maximum denominator as an integer, how to do it in mathematics? Many thanks.

+3
source share
2 answers

See help for Rationalize. RootApproximantmay also be useful

+3
source

Convergents continuation of fractions is a useful method for a better and better fractional representation of an irrational number. I also found them useful in understanding relationships with other ideas using the Euclidean algorithm .

pi .

ClearAll[approximate];

approximate[r_, nConvergents_: 8, precision_: 10] := 
   With[{c = Convergents[ContinuedFraction[r, nConvergents]]}, 
   TableForm[Transpose[{c, N[r - c, precision]}], 
   TableHeadings -> {None, {Row[{"approximation of ", r}], "error"}}]]

8 pi:

approximate[Pi]

approximate pi

8 Sqrt[2]:

approximate[Sqrt[2]]

approximate root 2

.

approximate .

Enjoy.


, .

+4

Source: https://habr.com/ru/post/1786569/


All Articles