【发布时间】:2022-01-17 16:20:00
【问题描述】:
我有三列数据(时间 (t)、推力 (T)、距离 (s)),我想从中计算完成的工作。包含数据的文本(logdata.txt)文件结构如下:
time, thrust, distance
1 2405 501
2 2500 702
3 2500 903
4 2580 1100
5 2610 1300
我遇到的示例仅显示了在为 f(x) 设置自己的函数时如何使用 scipy.integrate 函数,但是在这种情况下,我有原始数据(因此没有函数)。我想使用辛普森规则整合推力覆盖的距离。我使用的代码如下:
from scipy import integrate
import numpy as np
data = np.loadtxt("logdata.txt")
#selecting the whole second and third column of the text file
x = data[1]
y = data[2]
integrate.simps(y)
但是,这并没有给我一个合理的价值。有谁知道该怎么做?
【问题讨论】:
-
不应该是
integrate.simps(y=data[1], x=data[2])吗? -
你是对的
标签: python scipy simpsons-rule