How to use ode45 in this case?

1 view (last 30 days)
Elie Hatem
Elie Hatem on 28 May 2021
Edited: Elie Hatem on 28 May 2021
Hello,
I have the variable ydd (y double dot) that I want to integrate twice to get the variable y.
The formula of ydd is:
ydd = -tan(phi).*(zdd + gravity)
where phi, zdd are vectors of size (1xn) containing different angles and accelerations at each time instant.
And, gravity is also a vector of size (1xn) containing a constant value (which is 9.81) repeated n times.
So, ydd is also a (1xn) vector containing different accelerations at each time instant.
How can I use ode45 to integrate ydd twice?
Thank you for taking the time to read my question.

Accepted Answer

Torsten
Torsten on 28 May 2021
Edited: Torsten on 28 May 2021
ydot = y'(t0) + cumtrapz(t,-tan(phi).*(zdd+gravity));
y = y(t0) + cumtrapz(t,ydot),
plot(t,y)
where t is your (1xn) vector of times (t0,...,t_(n-1)) and y(t0) and y'(t0) are initial conditions (position and velocity at t=t0, respectively).
  3 Comments
Elie Hatem
Elie Hatem on 28 May 2021
Alright I will check and compare both solutions. Thanks for your help!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by