Comparison of symbolic expressions
14 次查看(过去 30 天)
显示 更早的评论
Welcome.
A certain set of symbolic calculations is performed in two different ways. After that, you need to compare the results (we want them to be equal). But using " eq " or "= = " you can't get the desired result. You can use a trick and subtract or divide the results, but this method does not always work correctly.
Is there a function for comparing symbolic calculations?
Example:
0 个评论
回答(2 个)
KSSV
2021-2-16
syms a b
c = a+b ;
d = b+a ;
isequal(c,d)
2 个评论
John D'Errico
2021-2-16
syms theta
isequal(sin(theta)^2 + cos(theta)^2,1)
Even worse, we see that while rewrite can seemingly improve this first counter-example, isequal still fails.
rewrite(sin(theta)^2 + cos(theta)^2,'sin')
isequal(rewrite(sin(theta)^2 + cos(theta)^2,'sin'),1)
The reason being that 1 and 1 are counter-intuitively not always seen to be equal, at least by isequal.
For this one, a carefully applied expand would have helped.
syms x
isequal((x+1)^3,x^3 + 3*x^2 + 3*x + 1)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!