simplify function does not work properly
조회 수: 6 (최근 30일)
이전 댓글 표시
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
채택된 답변
Paul
2022년 6월 15일
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.
추가 답변 (2개)
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)
% 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
참고 항목
카테고리
Help Center 및 File Exchange에서 Assumptions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!