How to find position function with acceleration function using matlab

24 views (last 30 days)
I have an equation:
x1_doubledot = -((k1+k2)/m1)*x1 + (k2/m1)*x2
where x1_doubledot is acceleration. I want to find the position function of this equation, what code should I use for MATLAB? Thank you

Answers (2)

John D'Errico
John D'Errico on 29 Sep 2022
Edited: John D'Errico on 29 Sep 2022
Just knowing the acceleration is meaningless, UNLESS you know how long the acceleration was in force. Next, acceleration is a vector thing. so you might hve x,y, nd z accelerations, all happening at once. If all you know is ONE acceleration, you can only infer position in one dimension.
Regardless, in order to compute position from acceleration, you compute the velocity first. So integrating acceleration gives you velocity, BUT only if you know the initial velocity. Otherwise, all you can infer is a change in velocity.
So use cumtrapz to integrate acceleration as a function of time, to get velocity. Then add in the initial velocity. Something like:
x1_dot = v0 + cumtrapz(t,x1_doubledot);
Then use cumtrapz again. But again, you need to know the initial position, otherwise all you can infer is a relative diplacememt.
x1 = x0 + cumtrapz(t,x1_dot);
And if your data lives in two or three dimensions, then you need to do all of this for each dimension.

Sam Chak
Sam Chak on 18 Oct 2022
Edited: Sam Chak on 18 Oct 2022
This ordinary differential equation is a linear type. So, it is actually a kind of eigenvalue/eigenvector problem.
If it is difficult to follow, the try using the dsolve() command. The position is given by the xSol(t).
syms x(t)
k1 = 3;
k2 = -2;
m1 = 1;
eqn = diff(x,t,2) == - ((k1 + k2)/m1)*x + (k2/m1)*diff(x,t);
Dx = diff(x,t);
cond = [x(0)==1, Dx(0)==0]; % initial condition
xSol(t) = dsolve(eqn, cond)
xSol(t) = 
fplot(xSol, [0 10]), grid on
xlabel('t'), ylabel('x(t)'), title('Position')


Find more on Matrix Computations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!