简体   繁体   中英

Mathematical equations with imported excel coordinates

I have like 10 or more x and y coordinates, and also an equation for them. And I can't figure out how make those calculations - especially a part with the equations. First of all, let's say there are 5 coordinates:

在Excel中

and I need to apply this equation:

方程式

The first one is the main, and those two others are for control check. How could I make it so it would read those coordinates and calculate according to equation? I tried:

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)

I am stuck at making calculations and managing the whole process after inputing values. Moreover, it needs to accept as many coordinates as there are and it counts the area plot.

The top equation seems to suggest that you would do:

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)

Is this what you had in mind? You would do something similar for the control equations.

EDIT: Added float conversion in the formulas above in case the data coming from excel is wrongly formatted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM