【发布时间】:2019-09-20 11:14:34
【问题描述】:
假设我有两个名为 x 和 y 的列表,它们都包含数字(坐标),请说:
x = [0, 1, 2, 3, 4, 4, 5]
y = [0, 1, 3, 3, 5, 6, 7]
我需要计算将这两个列表组合到 (x, y) 坐标时形成的曲线下面积。我真的不明白如何创建一个可以根据这些信息计算面积的函数。
即
def integrate(x, y):
""" x & y = lists, area_under_curve = float value of the area """
area_under_curve = 0
last_x = x[0]
last_y = y[0]
for cur_x, cur_y in list(zip(x, y))[1:]:
## some code here
return area_under_curve
【问题讨论】:
-
问题是离散点图而不是连续线。所以从技术上讲,从数学的角度来看,没有“曲线”。答案因使用的技术而异。使用梯形法则,左黎曼和、右黎曼和或中点都会产生不同的近似值。也许,python 有一些标准库可以解决这样的问题。