simplify function does not work properly
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Paul
le 15 Juin 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.
Plus de réponses (2)
Jan
le 14 Juin 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 commentaires
Voir également
Catégories
En savoir plus sur Assumptions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!