simplify function does not work properly
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Akzeptierte Antwort
Paul
am 15 Jun. 2022
Consider a simpler case
syms x y
term1 = x - 1;
term2 = y - 2;
eq = term1*term2
assume(term1*term2 == 0)
simplify(eq)
simplify(term1)
simplify(term2)
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
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)
% 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)
% simplify(children(eq).')
What exactly do you observe or expect instead?
0 Kommentare
Siehe auch
Kategorien
Mehr zu Assumptions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!