simplify function does not work properly

6 Ansichten (letzte 30 Tage)
Nieves Lopez
Nieves Lopez am 14 Jun. 2022
Kommentiert: Nieves Lopez am 15 Jun. 2022
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!

Akzeptierte Antwort

Paul
Paul am 15 Jun. 2022
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.

Weitere Antworten (2)

Jan
Jan am 14 Jun. 2022
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 am 14 Jun. 2022
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 Kommentare
Jan
Jan am 15 Jun. 2022
Is this an answer or a comment?
Nieves Lopez
Nieves Lopez am 15 Jun. 2022
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

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by