How to simplify a common factor in a symbolic equation

30 ビュー (過去 30 日間)
Kieran Corrigan
Kieran Corrigan 2020 年 5 月 18 日
コメント済み: Kieran Corrigan 2020 年 5 月 19 日
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
  2 件のコメント
John D'Errico
John D'Errico 2020 年 5 月 18 日
編集済み: John D'Errico 2020 年 5 月 18 日
The coef of the f_g term, meaning this expression from eq_4?
((I_2*R_1^2 + I_1*R_2^2)/(I_2*R_1^2 + I_1*R_2^2))
So now you wish to (programmatically) extract that coefficient, and set it to 1 as a new equation? I'll admit to being a bit lazy. I'd probably just use cut and paste, a far faster alternative to reading the help for the function coeffs. ;-)
Ok, I think you are saying that you see this expression is just the ratio of two numbers, which happen to be the same, and you are asking how to force MATLAB to recognize that X/X is just 1? Sometimes getting a computer to recognize what you see as obvious is harder than just using pencil and paper. But is that your question?
Kieran Corrigan
Kieran Corrigan 2020 年 5 月 18 日
Your edit is correct I’m trying to get matlab to recognise the coefficients of the f_g term are alike and cancel to 1.

サインインしてコメントする。

採用された回答

John D'Errico
John D'Errico 2020 年 5 月 18 日
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)
  1 件のコメント
Kieran Corrigan
Kieran Corrigan 2020 年 5 月 19 日
Yeah that seems to have resolved it, I did forget about the 0/0 case

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by