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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Alexander
el 14 de Mzo. de 2012
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 comentarios
Ver también
Categorías
Más información sobre Assumptions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!