无法将方程式转换为python代码

时间:2019-02-18 12:56:20

标签: python python-3.x python-2.7 math

这是我应该转换为代码的等式。

enter image description here

The output that I want to achieve

导入数学

def main():

x = 90
n= 0
sumk = 0
sumk1 = 0

while True:


    k = ((-1)**n/math.factorial(2*n+1)*float(math.radians(x))**(2*n+1))  
    k1 = (-1)**(n+1)/math.factorial(2*(n+1)+1)*float(math.radians(x))**(2*(n+1)+1)
    sumk1 = sumk + k1

    diff = abs(sumk - sumk1)
    print("k = {:d}, diff = {:.13f}, sin({:.1f}) = {:.13f}".format(n,diff,x,k))
    n = n + 1
    if diff < 10**-12:
        break
print("End Program")

main()

1 个答案:

答案 0 :(得分:1)

第一个总和= t(0) + t(1) ... + t(k)

第二个总和= t(0) + t(1) + ... + t(k) + t(k+1)

应该很容易看出区别只是t(k+1)

您可以将其绘制为x和k的函数,以查看随着添加的项的大小如何变化。