Today, I started working for the first time with solve_ivp. My problem is the following:
I have data from an accelerometer and speedometer ( variables a and v in the code), which correspond to the motion data of a body under a fluid. The governing equation of motion is:
Summarizing, what I want to do is:
and compare the recovered velocity with the original measured one.
I am using solve_ivp for this, and this is my code (I assumed that m=1, so I omited it in the calculations):
def obtainF(self, v, a):
return(a + self.coef * v**2)
def eqMot(self, t, y, F, coef):
return(F[t] - coef*y*y)
def diffSolver(self, F):
t = linspace(0,len(F)-1,len(F))
y0 = [0.0]
p = [F, self.coef]
sol = solve_ivp(self.eqMot, [0, len(F)-1], y0, args = p, t_eval=t)
return(sol.y[0])
(the code is pretty much self-explainatory). Code updated afterDavidJ answer (the issue remains)
The original acceleration and velocity are pretty much sinusoids with a small low-frequency offset. They are even low-pass filtered in advance in order to avoid any conflict with the solver.
The original and computed velocities do not mach. Not only that, but the missmatch seems to decrease when increasing 'coef'.
Obtained plot for 'coef' = 0.2:
And, here, for 'coef' = 1.5:
I am not understanding the origin of the issue. Any help will be welcome!
So I managed to solve the problem. As @LutzLehmann suggested in a comment, since I was taking the velocity measurements from one sensor and the acceleration data from a different one, even though at a first glance the later seemed the derivative of the former, in a sample-by-sample it turned out that there were significant differences between de (manually computed) derivative of speed and accel.
I solved it by mixing both sources of data with a complementary filter and working with the resulting velocity vector, differentiating it afterwards.
Thanks for the help!