簡體   English   中英

為什么我的代碼與我的計算器和在線計算器相比是錯誤的,有人可以告訴我它有什么問題嗎

[英]Why is my code wrong incomparsion to my calculator and online calculators can someone let me know whats wrong with it

 from math import cos
 from math import  sin
 from math import pi
 a0 = int(input("a0:"))
 b0 = int(input("b0:"))
 N = int(input("N:"))
 L = int(input("L:"))
 X = int(input("X:"))
 n = 0
 an = a0
 bn = b0
 y=0
 for i in range(N):
    n = n+1
    an = an + 10   
    bn = bn * 10   
    y = an * (cos(((n*pi*X)/(L))))+ (bn*(sin((n*pi*X)/(L))))
 total = a0 + y
 print(total)

我假設 y =.... 代碼是錯誤的,因為 an 和 bn 代碼工作正常 lmk方程

由於這是一個總和,因此您需要在循環內跟蹤它。 現在y只是最后一次迭代的結果。

 from math import cos
 from math import  sin
 from math import pi
 a0 = int(input("a0:"))
 b0 = int(input("b0:"))
 N = int(input("N:"))
 L = int(input("L:"))
 X = int(input("X:"))
 n = 0
 an = a0
 bn = b0
 y=0
 for i in range(N):
    n = n+1
    an = an + 10   
    bn = bn * 10   
    y += an * (cos(((n*pi*X)/(L))))+ (bn*(sin((n*pi*X)/(L))))
 total = a0 + y
 print(total)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM