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.
3 次查看(过去 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
0 个评论
回答(1 个)
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.
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!