MATLAB Answers

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

조회 수: 2(최근 30일)
Justin Burzachiello
Justin Burzachiello 2021년 7월 19일
편집: James Tursa 2021년 7월 20일
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: 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


James Tursa
James Tursa 2021년 7월 19일
편집: James Tursa 2021년 7월 19일
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];
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
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
James Tursa
James Tursa 2021년 7월 20일
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];
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.

댓글을 달려면 로그인하십시오.




Community Treasure Hunt

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

Start Hunting!

Translated by