Substitute specific expression that is not explicit in symbolic expression

13 views (last 30 days)
I have a symbolic expression like this:
syms g % Gravitational acceleration
syms t % Time
syms m_1 % Mass of Arm 1
syms m_2 % Mass of Arm 2
syms J_1 % Moment of Inertia of Arm 1 about center of mass
syms J_2 % Moment of Inertia of Arm 2 about center of mass
syms J_hat_1 % Moment of Inertia of Arm 1 about origin of coordinate system 1 (pivot point)
syms J_hat_2 % Moment of Inertia of Arm 2 about origin of coordinate system 2 (pivot point)
syms L_1 % Length of Arm 1
syms L_2 % Length of Arm 2
syms l_c_1 % The length from the center of rotation of Arm 1 to its center of mass.
syms l_c_2 % The length from the center of rotation of Arm 2 to its center of mass.
syms d_1 % Viscous damping of Arm 1 (motor rotor)
syms d_2 % Viscous damping of Arm 2 (between Arm 1 and Arm 2)
syms theta_1
syms theta_dot_1 % Temporal derivative of Theta 1, the angular velocity of arm 1
syms theta_ddot_1 % Second temporal derivative of Theta 1, the angular acceleration of arm 1
syms theta_2
syms theta_dot_2 % Temporal derivative of Theta 2, the angular velocity of arm 2
syms theta_ddot_2 % Second temporal derivative of Theta 2, the angular acceleration of arm 2
syms tau_1 % Torque applied by motor on beam
syms tau_2 % disturbance torque applied to arm 2
syms l_rot_1 % length between center of rotation and end of arm (positive x-direction)
syms l_rot_2 % length between center of rotation and end of arm (positive x-direction)
num = 8*J_1*tau_2 + 4*J_2*tau_2 + 4*l_c_2^2*m_2*tau_2 + 8*l_rot_1^2*m_1*tau_2 + 2*J_2^2*theta_dot_1^2*sin(2*theta_2) - J_2^2*theta_dot_1^2*sin(4*theta_2) - 4*J_2*tau_2*cos(2*theta_2) - 8*J_1*d_2*theta_dot_2 - 4*J_2*d_2*theta_dot_2 + 8*L_1^2*m_2*tau_2 + 4*J_1*J_2*theta_dot_1^2*sin(2*theta_2) + 2*l_c_2^4*m_2^2*theta_dot_1^2*sin(2*theta_2) - l_c_2^4*m_2^2*theta_dot_1^2*sin(4*theta_2) - 4*l_c_2^2*m_2*tau_2*cos(2*theta_2) - 6*g*l_c_2^3*m_2^2*sin(theta_2) - 8*L_1^2*d_2*m_2*theta_dot_2 - 4*d_2*l_c_2^2*m_2*theta_dot_2 - 8*d_2*l_rot_1^2*m_1*theta_dot_2 + 2*g*l_c_2^3*m_2^2*sin(3*theta_2) + 4*J_2*d_2*theta_dot_2*cos(2*theta_2) + 2*J_2*g*l_c_2*m_2*sin(3*theta_2) - 8*L_1^2*g*l_c_2*m_2^2*sin(theta_2) + 4*d_2*l_c_2^2*m_2*theta_dot_2*cos(2*theta_2) + 4*L_1^2*l_c_2^2*m_2^2*theta_dot_1^2*sin(2*theta_2) - 4*L_1^2*l_c_2^2*m_2^2*theta_dot_2^2*sin(2*theta_2) - 8*L_1*l_c_2*m_2*tau_1*cos(theta_2) - 8*J_1*g*l_c_2*m_2*sin(theta_2) - 6*J_2*g*l_c_2*m_2*sin(theta_2) + 4*J_2*L_1^2*m_2*theta_dot_1^2*sin(2*theta_2) + 4*J_1*l_c_2^2*m_2*theta_dot_1^2*sin(2*theta_2) + 4*J_2*l_c_2^2*m_2*theta_dot_1^2*sin(2*theta_2) - 2*J_2*l_c_2^2*m_2*theta_dot_1^2*sin(4*theta_2) + 4*J_2*l_rot_1^2*m_1*theta_dot_1^2*sin(2*theta_2) + 4*L_1*l_c_2^3*m_2^2*theta_dot_1*theta_dot_2*sin(theta_2) + 8*L_1*d_1*l_c_2*m_2*theta_dot_1*cos(theta_2) + 4*L_1*l_c_2^3*m_2^2*theta_dot_1*theta_dot_2*sin(3*theta_2) - 8*g*l_c_2*l_rot_1^2*m_1*m_2*sin(theta_2) + 4*l_c_2^2*l_rot_1^2*m_1*m_2*theta_dot_1^2*sin(2*theta_2) + 4*J_2*L_1*l_c_2*m_2*theta_dot_1*theta_dot_2*sin(theta_2) + 4*J_2*L_1*l_c_2*m_2*theta_dot_1*theta_dot_2*sin(3*theta_2)
I want to substitute then like this which does not work since subs does not reformulate before trying to subsitute:
subs(num, J_2 + m_2*(l_c_2)^2, J_hat_2)
The purpose is to introduce simplifying variables very much like subexpr does but with my own custom terms.
Thanks in advance for any help!

Answers (0)

Tags

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!