python - 使用数值积分找到坐标环所包围的区域
问题描述
我正在尝试查找或编写一些代码,可以为我提供两行之间的区域,如果较低的行与较高的行交叉,则说明负区域。为此(无法发布图像:()。我已经编写了代码,但对答案不是 100% 有信心。我也尝试使用 np.trapz 的 numpy 函数。
def TrapzCn(n):
Uy = Upper(n)
Ly = Lower(n)
xc = Open(L[0])
Top = np.trapz(Uy,x=xc[:10])
Bottom = np.trapz(Ly,x=xc[:10])
return(Top + Bottom)
这是我的
def Cn(n):
Uy = Upper(n)
xc = Open(L[0])
Ly = Lower(n)
for i in range(len(Ly)):
Ly[i] = float(Ly[i])
Uy[i] = float(Uy[i])
A = 0
i = 0
while i+1 < len(Uy):
A1 = (xc[i+1] - xc[i]) * ((Uy[i] + Uy[i+1])/2)
A2 = (xc[i+1] - xc[i]) * ((Ly[i] + Ly[i+1])/2)
if A1 > A2 and Uy[i] < 0.0 :
A += abs(A1) + abs(A2)
elif A1 > A2 and ((Uy[i] + Uy[i+1] )/2)> 0:
A += abs(A1) - abs(A2)
elif A1 < A2 and A1 < 0.0 :
A -= (abs(A2) - abs(A1))
i += 1
return(A)
Upper 和 Lower 函数只是在解压缩我的数据。所以我的主要问题是,np.trapz 函数是否解释了曲线本身翻倍以及它们交叉后的负区域。如果没有,我的呢?
解决方案
推荐阅读
- spring-boot - Kafka 消费者在处理一些消息时失败
- reactjs - React-Table - 如何从列标题中删除“Toggle sortBy”工具提示?
- css - 如何在 Angular 8 应用程序嵌套组件中实现多个粘性标题和一个滚动条?
- c# - WPF DataContext 在引用另一个 ViewModel 时返回 null
- c++ - 两个整数的幂
- embedded - 通过 AT+CSIM 发送 APDU 到 sim868
- javascript - 当组件在函数(钩子)之外定义时,React 不会更新 svg 中的多边形
- latex - 乳胶空白目录
- python - Sympy 表达式中复数的格式
- python - 如何用scrapy抓取视频?