MATLAB: Matrix form of system of equations with symbolic time dependant values

differentiatematrix formsymbolicsystem of equationstime

I have a system of equations with symbolic time dependant values:
t = sym('t');
q1(t)= sym('q1(t)');
q2(t) = sym('q2(t)');
x = diff(q1(t)*q2(t), t)
y = diff(q1(t)+q2(t)^2,t)
with the following output:
x =
q1(t)*diff(q2(t), t) + q2(t)*diff(q1(t), t)
y =
2*q2(t)*diff(q2(t), t) + diff(q1(t), t)
Is it possible to obtain the matrix form of these equations without doing it manually? something similar to this:
[q2(t), q1(t); 1, 2*q2(t)]*[diff(q1(t), t); diff(q2(t), t)]
Unfortunately, equationsToMatrix() doesn't seem to work in this case.
This example is relatively easy, but the equations I am working on are more complex and I would need some sort of automation. Any advise on working with symbolic math will be really appreciated.

Best Answer

You might have to work at the MuPAD level to do this efficiently.
Basically you would need to identify the diff() expressions and then substitute variables for them. Once you have them in the form of variables, you can ask for coefficients associated with the variable and use those to populate the matrix of coefficients you are building up.
If I were doing it in Maple I would probably use indets(x,specfunc(diff)) to identify the unique diff() expressions, but the indets() of the symbolic engine (MuPAD) is considerably less flexible in its type matching.