【问题标题】:Python: Integrating Data Point CurvePython:整合数据点曲线
【发布时间】:2021-08-01 22:27:56
【问题描述】:

我有一个 x,y,z 速度列表以及与每个值对应的时间域列表(时间步长不是恒定的)。我希望整合这些数据点集所描述的曲线,以获得数据点中的位置输出曲线。然后我可以通过我在侧面的初始位置(常量)来偏移曲线。

times       = np.asarray([0, 0.1, 0.3, 0.5, 3])
velocity_x  = np.asarray([1,  2 ,  3 ,  4 , 5])
position_x  = _integrate_(times,velocity_x)
position_c  = 100 #Constant initial position
position_x  += position_c

什么 Python 函数 (_integrate_()) 可用于这种类型的计算?我在 scipy 中看到了一些方法,但是,大多数似乎都处理定积分和/或符号函数。

谢谢

【问题讨论】:

    标签: python numpy scipy calculus


    【解决方案1】:

    假设你只是想要一个逐步的情节,这不是一个难题,对吧?

    import numpy as np
    import matplotlib.pyplot as plt
    
    def integrate( times, velocities ):
        pos = 0
        t0 = 0
        v0 = 0
        outp = [ ]
        for t,v in zip(times,velocities):
            deltat = t - t0
            pos += deltat * v0
            outp.append( pos )
            t0 = t
            v0 = v
        return outp
    
    times       = np.asarray([0, 0.1, 0.3, 0.5, 3])
    velocity_x  = np.asarray([1,  2 ,  3 ,  4 , 5])
    position_x  = integrate(times,velocity_x)
    print(position_x)
    plt.plot( times, position_x )
    plt.show()
    

    输出:

    timr@tims-gram:~/src$ python x.py
    [0.0, 0.1, 0.5, 1.1, 11.1]
    

    【讨论】:

      猜你喜欢
      • 2020-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-05
      • 1970-01-01
      • 1970-01-01
      • 2019-10-10
      • 2021-01-30
      相关资源
      最近更新 更多