对离散点进行积分的python程序实现,使用scipy执行样品的离散积分

I am trying to port from labview to python.

In labview there is a function "Integral x(t) VI" that takes a set of samples as input, performs a discrete integration of the samples and returns a list of values (the areas under the curve) according to Simpsons rule.

I tried to find an equivalent function in scipy, e.g. scipy.integrate.simps, but those functions return the summed integral across the set of samples, as a float.

How do I get the list of integrated values as opposed to the sum of the integrated values?

Am I just looking at the problem the wrong way around?

解决方案

I think you may be using scipy.integrate.simps slightly incorrectly. The area returned by scipy.integrate.simps is the total area under y (the first parameter passed). The second parameter is optional, and are sample values for the x-axis (the actual x values for each of the y values). ie:

>>> import numpy as np

>>> import scipy

>>> a=np.array([1,1,1,1,1])

>>> scipy.integrate.simps(a)

4.0

>>> scipy.integrate.simps(a,np.array([0,10,20,30,40]))

40.0

I think you want to return the areas under the same curve between different limits? To do that you pass the part of the curve you want, like this:

>>> a=np.array([0,1,1,1,1,10,10,10,10,0])

>>> scipy.integrate.simps(a)

44.916666666666671

>>> scipy.integrate.simps(a[:5])

3.6666666666666665

>>> scipy.integrate.simps(a[5:])

36.666666666666664

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值