[英]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.