python - 为什么我的代码与我的计算器和在线计算器相比是错误的,有人可以让我知道它有什么问题吗
问题描述
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 Equation
解决方案
由于这是一个总和,因此您需要在循环内跟踪它。现在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)
推荐阅读
- ocr - 管道 ghostscript dúvida
- php - PHP Laravel 7 Yarja Datatables 错误加载 800k+ 数据
- python - 如何使用 python matplotlib 绘制离散数据的直方图?
- r - 如何导入具有文本和数字日期格式的日期列的 Excel 电子表格?例如,(“2019 年 12 月 3 日”、“2019 年 5 月 4 日”、“43787”
- algorithm - 快速检查形状列表中相交量的算法
- sql - 数组中字符串整数的总和 - Postgres
- c++ - 在 C++ 代码中运行内置 octave 函数(使用 API)比在 Octave 中运行该函数需要更长的时间......为什么这样......?
- tstringgrid - 显示错误语法错误,意外的 T_String
- python - 使用黎曼和的中点规则计算 2 变量定积分的体积
- python - 是否可以使用python3检查是否存在受限文件?