无法将方程式转换为python代码[关闭]

问题描述 投票:-5回答:1

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

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")

主要()

python python-3.x python-2.7 math
1个回答
1
投票

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

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

应该很容易看出差异只是t(k+1)

您可以绘制为x和k的函数,以便在添加更多内容时查看术语的大小变化。

© www.soinside.com 2019 - 2024. All rights reserved.