I'm trying for a project to integrate acceleration data in order to have an approximation of the position. I used a real simple set of data to start with, with a constant acceleration.
from scipy.integrate import cumtrapz
t = [0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7]
a = [-9.8, -9.8, -9.8, -9.8, -9.8, -9.8, -9.8, -9.8, -9.8, -9.8, -9.8, -9.8, -9.8, -9.8, -9.8]
v = cumtrapz(a, t, initial=0)
z = cumtrapz(v, t, initial=5)
The result is quite satisfying, apart from the fact that the initial condition for the position is only respected for the first value, and I don't understand how I can change this ?

First of all,
scipy.integrate.cumtrapzis left for backward compatibility, you should use the newerscipy.integrate.cumulative_trapezoidfunction. Secondly, if you read the documentation you'll see thatinitialis not an initial condition but simply a value prepended onto the array, which would normally be one element shorter than the original data.There is also a deprecation warning that, starting version 1.12.0, providing anything but 0 or
Nonewill result in a warningThis shows the sizes of the result:
To enforce your initial condition, you should set
initial=0and then add the initial condition to the result.