带有导入excel坐标的数学方程

时间:2016-11-03 01:51:37

标签: python math plot coordinates

我喜欢10个或更多 x y 坐标,以及它们的等式。我无法弄清楚如何进行这些计算 - 特别是方程式的一部分。首先,让我们说有5个坐标:

In excel

我需要应用这个等式:

Equations

第一个是主要的,另外两个用于控制检查。我怎么能这样做它会读取那些坐标并根据等式计算?我试过了:

book = openpyxl.load_workbook('coordinates.xlsx')
sheet = book.active
for row_i in range(1, sheet.max_row + 1):
x_value = sheet.cell(row=row_i, column=1).value
y_value = sheet.cell(row=row_i, column=2).value
print(x_value,y_value)

在输入值后,我无法进行计算和管理整个过程。此外,它需要接受尽可能多的坐标,并计算面积图。

1 个答案:

答案 0 :(得分:0)

最上面的等式似乎暗示你会这样做:

two_p = 0
for row_i in range(1, sheet.max_row - 1):
    x_i = float(sheet.cell(row=row_i, column=1).value)
    y_plus1 = float(sheet.cell(row=row_i+1, column=2).value)
    y_minus1 = float(sheet.cell(row=row_i-1, column=2).value)
    two_p += x_i*(y_plus1 - y_minus1)
print(two_p)

这是你的想法吗?您可以为控制方程做类似的事情。

编辑:在上述公式中添加了float转换,以防来自excel的数据格式错误。