Cumtrapz integration drift with time
Ältere Kommentare anzeigen
Hello, I'm trying to get a displacement from a velocity. For a constant velocity, the formula is:
x_h = x_c + V*t
Where x_c is an initial value, V is the velocity magnitude and t is a time vector. Please note: the time vector t is linearly increasing. I now have a velocity u that is as below.

Theta is an azimuthal position, it is essentially related to time.
It starts from an undisturbed value (equal to V) then drops and recovers twice and at the end of the period (theta = 360 deg) it goes back to the undisturbed value. To compute the displacement, I do:
x_h = x_c + cumtrapz(u,t)
Below the displacements for constant velocity (formula with no integration) and non-constant velocity are plotted:

The issue is that, as you can see, cumtrapz drifts more and more away from the undisturbed value as time goes by. Consider that there's also another period preceding theta = 0 deg, so x_h is not starting at the undisturbed value at theta=0 deg, although it should. This would only happen if there was no drift introduced by cumtrapz. If I try to do:
x_h(t) = x_h(t-1) + u(t-1) dt(t-1)
I get basically the same. I checked that x_h(t) - x_h(t-1) behaves as the above-plotted u velocity, which is the case, so both the integral formulas are correct. However, I get the above-mentioned drift issue. Please note: u velocity is supposed to behave like that, its trend is not due to some sort of bias or noise in the data. How can I fix this, preferably keeping x_h(t) - x_h(t-1) behaving as the u velocity? Thanks for your help.
2 Kommentare
David Goodmanson
am 8 Dez. 2024
Hi Andrea,
This behavior is expected. Without the complications of angles, suppose you have an object moving at v1 m/sec but there is a portion tau seconds long where the object is is moving at a slower velocity v2 m/sec. The distance traveled in that portion will be v2*tau rather than v1*tau, so there will be a shortfall in distance of (v2-v1)*tau, and after the object is once again traveling at velocity v1, the shortfall will persist in a plot of distance vs time. That's the effect you are seeing with the red line dropping down between 200 and 300 degrees and then staying below the blue line by what should be a constant distance after that.
Andrea Improta
am 8 Dez. 2024
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



