How can I simplify complex symbolic equations? Simplify not working
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Anthony Stuart
le 18 Avr 2019
Commenté : Star Strider
le 18 Avr 2019
I'm having issues simplifying a large symbollic expression that Matlab outpiuts. I've tried using the simplify() command, but it doesn't seem to make any differences. Here's an example of the expression that I want to simplify:
syms R_s R_w r_w r_cm I_s I_r m_r m_s g tau
syms theta_s theta_b dtheta_s dtheta_b ddtheta_s ddtheta_b
eqn = (R_s*(I_r*R_s*r_w*tau - I_r*R_s*R_w*tau - I_r*R_s^2*tau + dtheta_b^2*m_r^2*r_cm^3*r_w*sin(theta_b + theta_s)^3 + dtheta_s^2*m_r^2*r_cm^3*r_w*sin(theta_b + theta_s)^3 - R_w*m_r*r_cm*tau*cos(theta_b + theta_s) - R_s^2*m_r*r_cm^2*tau*cos(theta_b + theta_s)^2 + m_r*r_cm*r_w*tau*cos(theta_b + theta_s) - R_s^2*m_r*r_cm^2*tau*sin(theta_b + theta_s)^2 + g*m_r^2*r_cm^2*r_w*cos(theta_b + theta_s)*sin(theta_b + theta_s) + 2*dtheta_b*dtheta_s*m_r^2*r_cm^3*r_w*sin(theta_b + theta_s)^3 + I_r*dtheta_b^2*m_r*r_cm*r_w*sin(theta_b + theta_s) + I_r*dtheta_s^2*m_r*r_cm*r_w*sin(theta_b + theta_s) - R_s*R_w*m_r*r_cm^2*tau*cos(theta_b + theta_s)^2 - R_s*R_w*m_r*r_cm^2*tau*sin(theta_b + theta_s)^2 + R_s*m_r*r_cm^2*r_w*tau*cos(theta_b + theta_s)^2 + R_s*m_r*r_cm^2*r_w*tau*sin(theta_b + theta_s)^2 + dtheta_b^2*m_r^2*r_cm^3*r_w*cos(theta_b + theta_s)^2*sin(theta_b + theta_s) + dtheta_s^2*m_r^2*r_cm^3*r_w*cos(theta_b + theta_s)^2*sin(theta_b + theta_s) + 2*dtheta_b*dtheta_s*m_r^2*r_cm^3*r_w*cos(theta_b + theta_s)^2*sin(theta_b + theta_s) + 2*I_r*dtheta_b*dtheta_s*m_r*r_cm*r_w*sin(theta_b + theta_s)))/(r_w*(I_s*R_s^2*m_r*r_cm^2*cos(theta_b + theta_s)^2 + I_s*R_s^2*m_r*r_cm^2*sin(theta_b + theta_s)^2 + I_r*I_s*R_s^2 + m_r^2*r_cm^2*sin(theta_b + theta_s)^2 + m_s*m_r*r_cm^2*cos(theta_b + theta_s)^2 + m_s*m_r*r_cm^2*sin(theta_b + theta_s)^2 + I_r*m_r + I_r*m_s));
simplify(eqn)
Just looking at this expression, I can see that there are sin^2(x)+cos^2(x) = 1 simplications that could be made, as well as terms that could be collected. Is there any way to make MATLAB do this for me, as opposed to me trying to do this by hand (and likely making errors)?
0 commentaires
Réponse acceptée
Star Strider
le 18 Avr 2019
Tell the simplify function to keep working on ‘eqn’ as long as necessary:
eqns = simplify(eqn, 'Steps',150)
producing:
eqns =
(sin(theta_b + theta_s)*(R_s*(r_w*dtheta_b^2*m_r^2*r_cm^3 + I_r*r_w*dtheta_b^2*m_r*r_cm + 2*r_w*dtheta_b*dtheta_s*m_r^2*r_cm^3 + 2*I_r*r_w*dtheta_b*dtheta_s*m_r*r_cm + r_w*dtheta_s^2*m_r^2*r_cm^3 + I_r*r_w*dtheta_s^2*m_r*r_cm) - R_s*g*m_r^2*r_cm^2*r_w*(2*sin(theta_b/2 + theta_s/2)^2 - 1)) - R_s*(I_r*R_s^2*tau + I_r*R_s*R_w*tau + R_s^2*m_r*r_cm^2*tau - I_r*R_s*r_w*tau + R_s*R_w*m_r*r_cm^2*tau - R_s*m_r*r_cm^2*r_w*tau) + R_s*(R_w*m_r*r_cm*tau - m_r*r_cm*r_w*tau)*(2*sin(theta_b/2 + theta_s/2)^2 - 1))/(r_w*(I_r*m_r + I_r*m_s + m_r^2*r_cm^2 + m_r*m_s*r_cm^2 + m_r^2*r_cm^2*(sin(theta_b + theta_s)^2 - 1) + I_r*I_s*R_s^2 + I_s*R_s^2*m_r*r_cm^2))
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Numbers and Precision dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!