MATLAB: Starting with a displacement function, can I use ODE 45 to calculate acceleration

accelerationdifferential equationsode45springspring damper

Hello,
I am trying to create a generic model for a spring-damper system that is experiencing base excitation. I want the function input to be the position/displacement function rather than a known velocity or acceleration.
I see a lot on here for ODE 45 for differential equations and integrating with a known velocity or acceleration. Is it possible to set it up to go the other way? I was hoping to see if there was a way to do this with ODE 45 instead of now just stating my function as the acceleration. I essentially want to create something that models the force transmitted to a mass from a known input. I thought there would be something already out there, but I just haven't found it yet. I may have just been staring at the problem too long.

Best Answer

You cannot differentiate data using a ODE solver.
Think of an ODE solver as a numerical integration tool. In fact, you can perform numerical integration using an ODE solver. So it is going the wrong way for what you want to do. Just because it has the word differential in it, does not mean it will differentiate your data.
If you have a displacement function, then simply differentiating it twice will give you acceleration. For example, if you take displacements in x and y as a function of time, then the first derivative will give you velocities in x and y. Then the second derivative will yield accelerations.
If you have data points that define the displacement, then you can use tools like gradient to differentiate the data, providing an approximate acceleration. Or you can interpolate the points using a spline, then differentiate it twice to yield an approximate acceleration.
In any case, remember that differentiation is a noise amplifying process, so any noise in the data will be amplified in the acceleration estimate.