Numerically integrating Acceleration to get displacement?

I want to rephrase my last question, as i was not very clear there.
What i am trying to do is integrate the following second order, nonlinear ode, which is an expression for angular acceleration,
twice, to get the displacement, and compare it with the actual expression for displacement:
BOTH ω and A are specified initially. They are constants.
------------------------------------equation for acceleration
(corrected from )
if initial conditions are required, then x(0)=pi/4 and dx/dt (t=0) =0
this has to be integrated w.r.t time, t, twice, between the limits t=0 and t=50 (it can be any time interval)
im not sure if the interval for x has to be defined as well.
the equation for displacement is
-----------------------------------------equation for displacement (corrected from
Any help would be appreciated!

 Réponse acceptée

Are you sure that the equations are correct? The solution you posted does not satisfy the initial conditions.
Generally, such a problem can be solved using the Symbolic toolbox
syms x(t) w A
dxdt = diff(x);
dx2dt2 = diff(x,2);
ode = dx2dt2 == -A*w*sin(dxdt);
cond = [x(0)==pi/4 dxdt(0)==0];
sol = dsolve(ode, cond)
or ode45() can be used for a numerical solution.

4 commentaires

KLETECH MOTORSPORTS
KLETECH MOTORSPORTS le 15 Nov 2020
Modifié(e) : KLETECH MOTORSPORTS le 15 Nov 2020
Could you please clarify what solution you are talking about?
Also, i was thinkig more along the terms of using "integral" or "cumtrapz"to solve this.
Basically, i need to integrate the acceleration equation twice to get displacement, and then plot that against the existing espression for displaceent, i.e, x= A*sin(w*t)
MY Mistake was taking w=dx/dt.
Very sorry.
w and A are constants, they are specified initially.
I have already solves the acceleration expression using ode45. Itsimplifies the acceleration equation into 2 linear ode's.
What i want to do here is integrate it.
Ameer Hamza
Ameer Hamza le 15 Nov 2020
Modifié(e) : Ameer Hamza le 15 Nov 2020
Yes, your question makes more sense after the correction. But still, there is the issue of the initial condition. You mentioned that the equation for displacement is
But you also mentioned, x(0)=pi/4. As you can see, that if you put t=0 in above equation, you cannot get pi/4.
In any case, you can use ode45(), which is used to solve ODEs. The reason you cannot use integral() or cumtrapz() is that they don't support initial conditions.
ode45() can be used like this
IC = [0; 0];
tspan = [0 10];
[t, y] = ode45(@odeFun, tspan, IC);
plot(t, y)
legend({'$x$', '$\dot{x}$'}, 'Interpreter', 'latex', 'FontSize', 16, 'Location', 'best')
function dxdt = odeFun(t,x)
A = 1;
w = 3;
dxdt = zeros(2,1);
dxdt(1) = x(2);
dxdt(2) = -A*w^2*sin(w*t);
end
I actually did use cumtrapz , and i think it worked, unless the logic is wrong:
i mistakenly used x=pi/4. what i should have said was A=pi/4. The amplitude is pi/4.
%this part integrates the acceleration(y1 = d^2(x)/dt^2) twice
% to get both velocity(y2) and displacement(y3)
t=0:0.01:2
w=15.24; %calculated using findwsq.m
A=pi/2;
y1=-A*(w.^2)*sin(w*t); %here y1 is diff(x,t,2) , i.e, accln
y2=cumtrapz(t,y1); %here y2 is diff(x,t) , i.e, velocity
y3=cumtrapz(t,y2); %here y3 is the
y3a= A*sin(w*t); %direct displacement expression
plot(t,y3, t,y3a)
Yes, in that case, initial conditions will be zero and you can use cumtrapz().

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by