简体   繁体   English

计算系列和精度之和 python

[英]calculate the sum of series and accuracy python

1 /1∙2 + 1/ 2∙3 + 1/ 3∙4 + ⋯ + 1 / (+1) +... ( find the sum of series and then find the accuracy according to formula given in the picture below) 1 /1∙2 + 1/ 2∙3 + 1/ 3∙4 +⋯ + 1 / (+1) +...(求级数之和,然后根据下图给出的公式求精度)

def sum(n):
i = 1.1
s = 1/1.2
for i in range(1, n + 1):
    s = s + 1 / i;
return s;
n = 5
print("Sum is", round(sum(n), 6))

Here is the formula for finding the accuracy这是找到准确性的公式

在此处输入图像描述

 1 0.1      0.637464
 2 0.001    0.685288
 3 0.0001   0.685782
 4 0.000001 0.685848

I believe you're asking why your code isn't working.我相信您在问为什么您的代码不起作用。 In that case, here's the working code.在这种情况下,这是工作代码。

def sum(n):
    sum = 0
    for i in range(1, n+1):
        sum += 1 / (i*(i+1))

    return sum

Not sure I understood your question... You mean you want to write that formula From the picture in Python code?不确定我是否理解你的问题......你的意思是你想从 Python 代码中的图片中写出那个公式?

I believe it is:我相信它是:

a=0
for i in range(1, n+1):
    a = a + ((i+1)**0.5) / (i*e)**i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM