simplify function does not work properly

조회 수: 6 (최근 30일)
Nieves Lopez
Nieves Lopez 2022년 6월 14일
댓글: Nieves Lopez 2022년 6월 15일
Hello,
I have an equation with 5 variables and a condition. Once I set the condition, when I simplify the equation, Matlab returns 0. However, this equation is the multiplication of some terms, but, when I try to simplify them separately, I do not get any 0.
Here is the code:
syms kd z mean_t mean_t2 p
assume(assumptions(),'clear');
eq = 8*kd^2*p^2*z*(mean_t - kd*mean_t2)^2*(- mean_t^2 + mean_t2)^2*(mean_t^2 - 2*kd*mean_t2*mean_t + mean_t2);
assume( p~=0 & kd*mean_t2*(3*p*mean_t^2 - 2*kd*mean_t2*p*mean_t + z + mean_t2*p) == p*mean_t^3 + mean_t2*p*mean_t + kd*mean_t2*z );
simplify(eq)
simplify(children(eq).')
Here is this code with some analytical simplifications:
syms kd z mean_t mean_t2 p
assume(assumptions(),'clear');
assume( 3*kd*mean_t2*mean_t^2 - 2*kd^2*mean_t2^2*mean_t + kd*mean_t2^2 - mean_t^3 - mean_t2*mean_t == 0 )
eq = (mean_t - kd*mean_t2)^2 * (mean_t^2 - 2*kd*mean_t2*mean_t + mean_t2);
simplify(eq)
simplify(children(eq).')
I'm running R2016b
Any help with this? Thank you very much!

채택된 답변

Paul
Paul 2022년 6월 15일
Consider a simpler case
syms x y
term1 = x - 1;
term2 = y - 2;
eq = term1*term2
eq = 
assume(term1*term2 == 0)
simplify(eq)
ans = 
0
simplify(term1)
ans = 
simplify(term2)
ans = 
Because of the assumption, simplify() "knows" that the eq is zero, basically because that's what we've explicitly asserted via the assumption. Is that assumption sufficient to assert that x == 1? Or y == 2? Or both? To be sure, one or both must be true, but how should Matlab choose which of the three possibilities to enforce?
I'm guessing a similar behavior is in effect in for the code in the Question.

추가 답변 (2개)

Jan
Jan 2022년 6월 14일
syms kd z mean_t mean_t2 p
assume(assumptions(),'clear');
eq = 8*kd^2*p^2*z*(mean_t - kd*mean_t2)^2 * ...
(- mean_t^2 + mean_t2)^2*(mean_t^2 - 2*kd*mean_t2*mean_t + mean_t2);
assume( p~=0 & ...
kd*mean_t2*(3*p*mean_t^2 - 2*kd*mean_t2*p*mean_t + z + mean_t2*p) == ...
p*mean_t^3 + mean_t2*p*mean_t + kd*mean_t2*z );
simplify(eq)
ans = 
0
% simplify(children(eq).')
syms kd z mean_t mean_t2 p
assume(assumptions(),'clear');
assume( 3*kd*mean_t2*mean_t^2 - 2*kd^2*mean_t2^2*mean_t + ...
kd*mean_t2^2 - mean_t^3 - mean_t2*mean_t == 0 )
eq = (mean_t - kd*mean_t2)^2 * (mean_t^2 - 2*kd*mean_t2*mean_t + mean_t2);
simplify(eq)
ans = 
0
% simplify(children(eq).')
Check for incorrect argument data type or missing argument in call to function 'simplify'.
What exactly do you observe or expect instead?

Nieves Lopez
Nieves Lopez 2022년 6월 14일
syms kd z mean_t mean_t2 p
assume(assumptions(),'clear');
assume( 3*kd*mean_t2*mean_t^2 - 2*kd^2*mean_t2^2*mean_t + ...
kd*mean_t2^2 - mean_t^3 - mean_t2*mean_t == 0 )
eq = (mean_t - kd*mean_t2)^2 * (mean_t^2 - 2*kd*mean_t2*mean_t + mean_t2);
simplify(children(eq).')
ans =
(mean_t - kd*mean_t2)^2
mean_t^2 - 2*kd*mean_t2*mean_t + mean_t2
(copied the result from the Matlab command window, since in R2016b the behaviour of simplify was slightly different)
Thank you for the answer. What I mean is that eq is the product of two terms, none of them are simplified to 0. However, the whole expression does get simplificated to 0. If a*b=0, then a=0 or b=0, but i this case neither a nor b are0.
  댓글 수: 2
Jan
Jan 2022년 6월 15일
Is this an answer or a comment?
Nieves Lopez
Nieves Lopez 2022년 6월 15일
Sorry that I was not clear. I don't see how it is possible to have both simplify(mean_t - kd*mean_t2)~=0 and simplify(mean_t^2 - 2*kd*mean_t2*mean_t + mean_t2)~=0, and the product simplify((mean_t - kd*mean_t2)*(mean_t^2 - 2*kd*mean_t2*mean_t + mean_t2))==0

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by