MATLAB: How to simplify a common factor in a symbolic equation

simplifyingsymbolic

My code is as follows
syms I_1 phi_1_d2 R_1 f_g mu_1 I_2 phi_2_d2 R_2 mu_2
eq_1= mu_1== I_1 * phi_1_d2 + R_1 * f_g;
eq_2= mu_2== I_2 * phi_2_d2 - R_2 * f_g;
eq_1= expand(eq_1 * (I_2 * R_1));
eq_2= expand(eq_2 * (I_1 * R_2));
eq_3= eq_1 - eq_2;
eq_3= collect(eq_3, [I_1, I_2]);
eq_3= collect(eq_3, f_g);
eq_4= eq_3 / ((I_2 * (R_1 ^2)) + (I_1 * (R_2 ^2)));
eq_4= collect(eq_4, f_g)
With the output being
eq_4 =
(R_1*mu_1*I_2 + (-R_2*mu_2)*I_1)/(I_2*R_1^2 + I_1*R_2^2) == ((I_2*R_1^2 + I_1*R_2^2)/(I_2*R_1^2 + I_1*R_2^2))*f_g + (I_1*I_2*(R_1*phi_1_d2 - R_2*phi_2_d2))/(I_2*R_1^2 + I_1*R_2^2)
This is correct as far as I can tell, however I'm unsure how to make matlab recognise that the coefficient for the f_g term is 1
Any help would be appreciated, I am new to MATLAB and unfamiliar with the symbolic toolkit

Best Answer

Its still easier to just use cut and paste. ;-) Damn these computers. I want my slide rule back!
As I said, sometimes it gets complicated to tell the computer what seems obvious. What happens if I try this:
simplify(expand(eq_4))
ans =
I_2*R_1^2 + I_1*R_2^2 ~= 0 & I_2*(R_1*mu_1 + I_1*R_2*phi_2_d2) == I_2*f_g*R_1^2 + I_1*I_2*phi_1_d2*R_1 + I_1*f_g*R_2^2 + I_1*mu_2*R_2
Now we see an anded expression, thus:
I_2*R_1^2 + I_1*R_2^2 ~= 0
AND
I_2*(R_1*mu_1 + I_1*R_2*phi_2_d2) == I_2*f_g*R_1^2 + I_1*I_2*phi_1_d2*R_1 + I_1*f_g*R_2^2 + I_1*mu_2*R_2
The problem is X/X is not ALWAYS 1. When X == 0, we have a problem, and then MATLAB gets obstinate, worrying about the singular case where X == 0. It could happen.
But I think this is what you need:
combine(eq_4)
ans =
(I_2*R_1*mu_1 - I_1*R_2*mu_2)/(I_2*R_1^2 + I_1*R_2^2) == f_g + (I_1*I_2*(R_1*phi_1_d2 - R_2*phi_2_d2))/(I_2*R_1^2 + I_1*R_2^2)