[英]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)
Im assuming that the y =.... code is wrong since the an and bn code works fine lmk Equation我假设 y =.... 代码是错误的,因为 an 和 bn 代码工作正常 lmk方程
Since this is a sum you need to be keeping track of that inside the loop.由于这是一个总和,因此您需要在循环内跟踪它。 Right now
y
will just be the result of that last iteration.现在
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.