如何圆周率(π)计算出来的? [英] How is pi (π) calculated?

查看:121
本文介绍了如何圆周率(π)计算出来的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何写一个函数将返回圆周率(π)的小数位数给定数?

How can I write a function which will return pi (π) to a given number of decimal places?

编辑:速度不是一个问题。我一直在寻找 http://bellard.org/pi/ ,但我还是不明白如何得到圆周率的第n个位数。

Speed is not a concern. I've been looking at http://bellard.org/pi/, but I still don't understand how to get the nth digit of pi.

推荐答案

在演算有一个叫泰勒系列的东西它提供了一种简单的方法来计算诸多不合理值任意precision。

In calculus there is a thing called Taylor Series which provides an easy way to calculate many irrational values to arbitrary precision.

π/ 4 = 1 - 1/3 + 1/5 - 1/7 + ...
(从<一个href="http://www.math.hmc.edu/funfacts/ffiles/30001.1-3.shtml">http://www.math.hmc.edu/funfacts/ffiles/30001.1-3.shtml )

Pi/4 = 1 - 1/3 + 1/5 - 1/7 + ...
(from http://www.math.hmc.edu/funfacts/ffiles/30001.1-3.shtml )

请加入这些条款,直到你想要稳定的precision位数。

Keep adding those terms until the number of digits of precision you want stabilize.

泰勒定理是一种强大的工具,但这个系列使用定理的推导是超出的问题的范围。这是标准的大学一年级的微积分,是如果你想了解更多的细节容易googlable。

Taylor's theorem is a powerful tool, but the derivation of this series using the theorem is beyond the scope of the question. It's standard first-year university calculus and is easily googlable if you're interested in more detail.

编辑:我并不是在暗示,这是最实用的方法来计算圆周率。这将取决于为什么你真的需要做到这一点。为了实用的目的,你应该就像你从许多已发表的版本中的一个需要复制尽可能多的数字。我建议这是一个简单的介绍了如何不合理的值可以等同于无穷级数。

I didn't mean to imply that this is the most practical method to calculate pi. That would depend on why you really need to do it. For practical purposes, you should just copy as many digits as you need from one of the many published versions. I was suggesting this as a simple introduction of how irrational values can be equated to infinite series.

这篇关于如何圆周率(π)计算出来的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆