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!