Hi Elio
The issue you're encountering is related to the coeffs function in MATLAB, which is designed to extract coefficients of polynomials. However, if it is used with non-polynomial expressions (like products of derivatives), it can lead to errors.
Kindly refer to the following code snippets to understand where the changes have to be made in the provided code to address this issue.
1. Define Temporary Variables
syms dtheta1 dpsi1 dxh
2. Replace the derivative terms in your expression with these temporary variables
DdT_xhdot_dT_sub = subs(DdT_xhdot_dT, ...
[diff(xh, t, t), diff(theta1(t), t, t), diff(psi1(t), t, t), diff(theta1(t), t), diff(psi1(t), t)], ...
[dxh, dtheta1, dpsi1, dtheta1, dpsi1]);
3. Simplify the expression after substitution
DdT_xhdot_dT_simplified = simplify(DdT_xhdot_dT_sub);
4. Extract the coefficients by substituting back to isolate each term
coeff_xh_tt = subs(DdT_xhdot_dT_simplified, [dtheta1, dpsi1, dxh], [0, 0, 1]);
coeff_theta1_tt = subs(DdT_xhdot_dT_simplified, [dtheta1, dpsi1, dxh], [1, 0, 0]);
coeff_psi1_tt = subs(DdT_xhdot_dT_simplified, [dtheta1, dpsi1, dxh], [0, 1, 0]);
coeff_theta1_dpsi1 = subs(DdT_xhdot_dT_simplified, [dtheta1, dpsi1, dxh], [1, 1, 0]);
5. Finally, display the coefficients as needed
coeff_xh_tt
coeff_theta1_tt
coeff_psi1_tt
coeff_theta1_dpsi1
For more information regarding the subs function, kindly refer the following documentation - https://www.mathworks.com/help/symbolic/sym.subs.html
I hope this resolves the issue.
