High precision rational fraction approximation
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mehdi
le 10 Sep 2014
Modifié(e) : John D'Errico
le 15 Oct 2014
I need to convert some high precision numbers to rational numbers. There is a function available in MATLAB called rat which does this for double precision numbers. For example if there are a couple of numbers different beyond the double precision decimal digits, then rat gives the same result. I tried to fix this by reducing the tolerance but it did not help. Is there any solutions available for this?
If I could have access to the source code of rat it would be possible to update it for high precision numbers as well.
6 commentaires
Réponse acceptée
John D'Errico
le 15 Oct 2014
Modifié(e) : John D'Errico
le 15 Oct 2014
I decided to get this working. Easy enough. And since I had to post a bug fix for something in HPF anyway, I pushed it to the top of my list.
So in the most recently uploaded version of HPF, there is now a rat function, using a continued fraction approximation to any HPF floating point number. It uses a few divides, so while I'd like it to be faster, it works nicely for numbers on the order of a few hundred digits in precision.
[N,D] = rat(hpf('pi',100),hpf('1e-101'))
N =
394372834342725903069943709807632345074473102456264
D =
125532772013612015195543173729505082616186012726141
N/D
ans =
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
hpf('pi',100)
ans =
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Number Theory dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!