HTML Diff
0 added 1 removed
Original 2026-01-01
Modified 2026-02-26
1 <h2>Ответы</h2>
1 <h2>Ответы</h2>
2 <p>Число Пи может быть вызвано с помощью константы pi встроенного в Python пакета<em>math</em>.</p>
2 <p>Число Пи может быть вызвано с помощью константы pi встроенного в Python пакета<em>math</em>.</p>
3 - <p>0</p>
 
4 <p>Мало ли кому интересно. Формула для вычисления любого количества знаков после запятой на питоне.</p>
3 <p>Мало ли кому интересно. Формула для вычисления любого количества знаков после запятой на питоне.</p>
5 <p>from mpmath import mp, sqrt, mpf, pi, log10, fabs # decimal_place = значение знаков после запятой decimal_places = 100000 mp.dps = decimal_places epsilon = 1/mpf(10**decimal_places) # set a = 1 and b = 1/sqrt(2) as multi-precision numbers a = mpf(1) b = 1/sqrt(mpf(2)) diff = a - b series = mpf(0) n = 0 while diff &gt; epsilon: n += 1 arith = (a + b)/2 geom = sqrt(a*b) a, b = arith, geom series += 2**(n+1) * (a*a - b*b) diff = a - b # a and b have converged to the AGM my_pi = 4*a*a/(1 - series) error = fabs(pi - my_pi) decimal_places = int(-log10(error)) print("Number of steps used: %d" % n) print("Number of correct decimal places: %d" % decimal_places) print(pi)</p>
4 <p>from mpmath import mp, sqrt, mpf, pi, log10, fabs # decimal_place = значение знаков после запятой decimal_places = 100000 mp.dps = decimal_places epsilon = 1/mpf(10**decimal_places) # set a = 1 and b = 1/sqrt(2) as multi-precision numbers a = mpf(1) b = 1/sqrt(mpf(2)) diff = a - b series = mpf(0) n = 0 while diff &gt; epsilon: n += 1 arith = (a + b)/2 geom = sqrt(a*b) a, b = arith, geom series += 2**(n+1) * (a*a - b*b) diff = a - b # a and b have converged to the AGM my_pi = 4*a*a/(1 - series) error = fabs(pi - my_pi) decimal_places = int(-log10(error)) print("Number of steps used: %d" % n) print("Number of correct decimal places: %d" % decimal_places) print(pi)</p>
6 <p>Исходник<a>http://www.johndcook.com/blog/2012/06/03/calculating-pi-with-agm-and-mpmath/</a></p>
5 <p>Исходник<a>http://www.johndcook.com/blog/2012/06/03/calculating-pi-with-agm-and-mpmath/</a></p>