Created
September 17, 2019 14:14
-
-
Save worldmind/93ebf4e38ef291201b568ba06db07d53 to your computer and use it in GitHub Desktop.
Muller's recurrence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from decimal import Decimal | |
from fractions import Fraction | |
def muller_recurrence(y, z): | |
return 108 - ((815-1500/z)/y) | |
N = 25 | |
x_prev = 4 | |
x_curr = 4.25 | |
x_prev_dec = Decimal(4) | |
x_curr_dec = Decimal(17)/Decimal(4) | |
x_prev_frac = Fraction(4) | |
x_curr_frac = Fraction(17, 4) | |
for i in range(2, N+1): | |
x_next = muller_recurrence(x_curr, x_prev) | |
x_prev, x_curr = x_curr, x_next | |
x_next_dec = muller_recurrence(x_curr_dec, x_prev_dec) | |
x_prev_dec, x_curr_dec = x_curr_dec, x_next_dec | |
x_next_frac = muller_recurrence(x_curr_frac, x_prev_frac) | |
x_prev_frac, x_curr_frac = x_curr_frac, x_next_frac | |
print(f"{i} | {x_next} | {x_next_dec} | {float(x_next_frac)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(EN) The problem of rounding a row of irrational numbers: https://latkin.org/blog/2014/11/22/mullers-recurrence-roundoff-gone-wrong/
(RU) Проблема округления ряда иррациональных чисел: https://habr.com/post/258483/