帮助估计pi = sqrt的值(6 *(1 /(1)2 + 1 /(2)2 + 1 /(3)2+ 1 /(4)2 + 1 /( [英] Help with apppproximate value of pi = sqrt(6* (1/(1)2 + 1/(2)2 + 1/(3)2+ 1/(4)2 + 1/(

查看:83
本文介绍了帮助估计pi = sqrt的值(6 *(1 /(1)2 + 1 /(2)2 + 1 /(3)2+ 1 /(4)2 + 1 /(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

本周我在我的一个实验室工作,计算pi的近似值。下面列出的是我在这里发布的实际问题,以便您可以看到该程序的不同要求。


程序很简单。我使用了?for循环?定义增量数,然后设置公式来计算pi。我的代码编译没有问题,但结果不正确。我使用的测试数据之一是100(术语),这应该导致3.13592904(或接近此值)。我的代码返回19.7060531358098的结果。


我很感激你们的任何帮助。谢谢。




pi = sqrt(6 *(1 /(1)2 + 1 /(2)2 + 1 /(3)2 + 1 /(4)2 + 1 /(5)2 + ...... + 1 /(n)2))其中n是术语数。


本实验的问题是使用上述系列编写一个近似pi的程序(使用for循环)。允许用户指定要使用的术语的编号n。尝试使用n = 100,然后是1,000,然后是10,000的程序。


注意随着增加术语数量,近似值会变得越来越好。出于比较目的,pi到15位小数的正确值是3.141592653589793。您的程序无法获得这种准确性,但为了获得最佳精度,可以使整数数据类型为long,浮点数据类型为long。


重要提示:为了在自动评分系统中正确运行,必须将输出精度设置为15,并为所有变量使用正确的数据类型。



Hello
I am working on one of my lab for this week, which calculates the approximate value of pi. Listed below is the actual problem, which I am posting here, so that you can see the different requirements for the program.

The program is simple. I used the ?for loop? to define the number of increments, then set up a formula to calculate the pi. My codes compile with no problem, but the result is incorrect. One of the test data I used was 100 (terms), which should result in 3.13592904 (or something close to this). My codes return a result of 19.7060531358098.

I would appreciate any help from you guys. Thanks.



pi = sqrt(6* (1/(1)2 + 1/(2)2 + 1/(3)2+ 1/(4)2 + 1/(5)2 +...... + 1/(n)2)) where n is the number of terms.

Your problem for this lab is to write a program (using a for loop) that approximates pi using the above series. Allow the user to specify the number, n, of terms to be used. Try your program with n = 100, then 1,000, then 10,000.

Note how the approximation becomes better and better as you increase the number of terms. For comparison purposes, the correct value of pi to 15 decimal places is 3.141592653589793. You won?t get that kind of accuracy with your program, but to get the best accuracy possible make your integer datatypes long and your floating point datatypes long double.

Important: In order to run correctly in the Automatic Grading System, you must set your output precision to 15 and use the correct datatypes for all your variables.





展开 | 选择 | Wrap | 行号

推荐答案

展开 | 选择 | Wrap | 行号


展开 | 选择 | 换行 | 行号


不要过多担心代码标签 - 请继续阅读我们的发布指南


无论如何,我想我找到了你的问题。在作业规范中,它表示取最终答案的平方根,我不认为你这样做。


但是,如果答案是〜15,那么你的答案是最终结果可能会接近4比3 ......但它会更接近你的答案。
Don''t worry too much about the code tags - just go ahead and read our Posting Guidelines when you get the chance.

Anyway, I think I found your problem. In the assignment specification, it says to take the square root of your final answer, which I don''t see you doing.

However, if your answer is ~15, then your final result will probably be closer to 4 than 3...It will be yet closer to your answer, though.


这篇关于帮助估计pi = sqrt的值(6 *(1 /(1)2 + 1 /(2)2 + 1 /(3)2+ 1 /(4)2 + 1 /(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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