注意:我已经阅读过此主题,但我不知道不理解它并且它没有提供我可以使用的解决方案。我对数字问题感到很糟糕。
将 Pi 生成用户想要的小数位数的简单方法是什么?这不是家庭作业,只是尝试完成此处列出的一些项目:
链接
Note: I've already read this topic, but I don't understand it and it doesn't provide a solution I could use. I'm terrible with number problems.
What's a simple way to generate Pi to what number of decimals a user wants? This isn't for homework, just trying to complete some of the projects listed here:
Link
发布评论
评论(3)
计算 pi 数字的经典算法是 Gauss-Legendre 算法。虽然它不如一些更现代的算法那么快,但它确实具有易于理解的优点。
Let
then
then
Here(
=.
表示“大约等于”)该算法表现出二次收敛(每次迭代时正确的小数位数加倍)。我将让您将其转换为 C#,包括发现任意精度算术库。
A classic algorithm for calculating digits of
pi
is the Gauss-Legendre algorithm. While it is not as fast as some of the more modern algorithms it does have the advantage of being understandable.Let
Then
Then
Here (
=.
means "approximately equal to") This algorithm exhibits quadratic convergence (the number of correct decimal places doubles with each iteration).I'll leave it to you to translate this to C# including discovering an arbitrary-precision arithmetic library.
您谈论的主题使用泰勒级数计算 PI 值。使用该主题中编写的函数“double F (int i)”将为您提供“i”项后的 PI 值。
这种计算 PI 的方法有点慢,我建议您查看 PI快速算法。
您还可以在此处找到一种实现,可将 PI 计算到第 n 位。
祝你好运!
The topic your talking about calculate the value of PI using the taylor series. Using the function "double F (int i)" wrote on that topic will give you the value of PI after "i" terms.
This way of calculating PI is kind of slow, i suggest you to look at the PI fast algorithm.
You can also find one implementation here that get the calculate PI to the n th digit.
Good luck!
如果您仔细研究这个非常好的指南:
并行编程模式:使用 .NET Framework 4 理解和应用并行模式
您将在第 70 页找到这个可爱的实现(我这边做了一些细微的更改):
If you take a close look into this really good guide:
Patterns for Parallel Programming: Understanding and Applying Parallel Patterns with the .NET Framework 4
You'll find at Page 70 this cute implementation (with minor changes from my side):