필터 지우기
필터 지우기

Problems using the equality indicator in the Symbolic Toolbox. Matlab returns 0 when I check the equality of 2 terms. At the same time it returns 1 for the ratio of the same terms.

조회 수: 2 (최근 30일)
O =
(y1*y2*(T + b_1*lambda - b_ss*lambda - 1))/(a*(y2 + k^psi)^((psi - 1)/psi) - y1*y2 + T*y1*y2 + b_1*lambda*y1*y2 - b_ss*lambda*y1*y2)
>> mu2
mu2 =
1/((a*(y2 + k^psi)^((psi - 1)/psi))/(y1*y2*(T + lambda*(b_1 - b_ss) - 1)) + 1)
>> simplify(O/mu2)
ans =
1
>> simplify(O)==simplify(mu2)
ans =
0
>> factor (O) == factor (mu2)
ans =
0
>> factor (simplify (O)) == factor (simplify(mu2))
ans =
0

답변 (1개)

Alexander
Alexander 2012년 3월 14일
That's because '==' compares syntactically and the symbolic expressions still differ a little, though they have the same value where both are defined. Please note that strictly speaking, mu2 is not defined for y1=0 (you have a divison by zero). It is not possible to guarantee, that two equivalent symbolic expression look the same or can be simplified to the same expression.
Starting with 2012a you can use the function 'isAlways' to compare two sym objects in a mathematical meaning:
>> isAlways(O==mu2)
ans =
1
If you use an older version, I suggest to simplify the difference and compare to zero:
>> simplify(O-mu2) == 0
ans =
1
However this may still fail, if your input is very complicated and 'simplify' does not recognize a zero.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by