How can I model equation of motion (2nd order ODE) when system matrices are in terms of state variables?

3 vues (au cours des 30 derniers jours)
Hello. Hello. I'd like to simulate a 2 degree of freedom system with arbitrary initial conditions. However, the equation of motion has matrices that are dependent on the state variables that the equation of motion models. This confuses me since I have only modeled systems that have matrices independent of state variables so far.
I have recently been able to model a similar ODE through ode15 (link to question that I asked to do that: https://www.mathworks.com/matlabcentral/answers/878893-how-can-i-model-second-order-ode-with-matrices-and-external-forcing?s_tid=srchtitle) However, the matrices in that were not in terms of the q, qdot, or qdotdot, as they are in the attched picture. Does anyone know what I may be able to do?
I have attached a diagram of the robot that exhibits these dynamics. This begins on page 119 of the attached pdf.
  • Thank you

Réponses (1)

James Tursa
James Tursa le 19 Juil 2021
Modifié(e) : James Tursa le 19 Juil 2021
Yes you can have derivative functions that depend on state variables. This is quite common. E.g., define a 4x1 state vector y that is composed of stacked 2x1 q and 2x1 qdot. Then your derivative function for 4x1 ydot would look like this:
function ydot = qderivative(t,y, other stuff goes here)
q = y(1:2);
qdot = y(3:4);
M = your 2x2 matrix function of q
C = your 2x2 matrix function of q and qdot
g = your 2x1 vector function of q
tau = your 2x1 right hand side vector
qdotdot = M \ (tau - C*qdot - g);
ydot = [qdot;qdotdot];
end
The "other stuff" would be the constants in your problem. E.g., m1, m2, I1, I2, etc. Then the function handle you would use at the calling level would be:
m1 = something
m2 = something
I1 = something
I2 = something
etc.
dy = @(t,y) qderivative(t,y,m1,m2,I1,I2, etc );
The (t,y) signature of this function handle matches what the MATLAB integration functions expect.
  2 commentaires
Justin Burzachiello
Justin Burzachiello le 20 Juil 2021
Thank you, James. For writing my matrices, such as M, can you elaborate on how to tell MATLAB that there is a state variable in usage, and not a constant?
Let's say that I have
M = [ a, a*b; a*q1, q2dot]
where a and b are constants, and q = [q1, q2, q1dot, q2dot]^T.
Should I write M as the following, where I explicitly state that the q1 and q2dot are from my state vector?
a = 1; b = 2;
M = [1, 2; q(1,1), q(4,1)]
James Tursa
James Tursa le 20 Juil 2021
Modifié(e) : James Tursa le 20 Juil 2021
You simply use the q and qdot from the state vector y as I have defined them in my example code. The constants are passed in as extra arguments. E.g.,
function ydot = qderivative(t,y, m1, m2, l1, lc1, lc2, etc )
q = y(1:2);
qdot = y(3:4);
C11 = -m2 * l1 * lc2 * sin(q(2)) * qdot(2);
C12 = -m2 * l1 * lc2 * sin(q(2)) * (qdot(1) + qdot(2));
C21 = m2 * l1 * lc2 * sin(q(2)) * qdot(1);
C22 = 0;
C = [C11,C12;C21,C22];
etc.
Remember, your 4x1 state vector y is defined as
y(1) = q1
y(2) = q2
y(3) = qdot1
y(4) = qdot2
The constants m1, m2, l1, etc are defined in the caller and simply passed in as extra arguments.

Connectez-vous pour commenter.

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by