2 views (last 30 days)

Show older comments

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

James Tursa
on 19 Jul 2021

Edited: James Tursa
on 19 Jul 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.

James Tursa
on 20 Jul 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.

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

Start Hunting!