필터 지우기
필터 지우기

Comparison of symbolic expressions

조회 수: 14 (최근 30일)
reincornator
reincornator 2021년 2월 16일
댓글: reincornator 2021년 2월 16일
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:

답변 (2개)

KSSV
KSSV 2021년 2월 16일
syms a b
c = a+b ;
d = b+a ;
isequal(c,d)
ans = logical
1
  댓글 수: 2
John D'Errico
John D'Errico 2021년 2월 16일
syms theta
isequal(sin(theta)^2 + cos(theta)^2,1)
ans = logical
0
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')
ans = 
1
isequal(rewrite(sin(theta)^2 + cos(theta)^2,'sin'),1)
ans = logical
0
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)
ans = logical
0
reincornator
reincornator 2021년 2월 16일
isequal(expand((x+1)^3),x^3 + 3*x^2 + 3*x + 1)

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2021년 2월 16일
isAlways(c == d, 'Unknown', false)
  댓글 수: 1
reincornator
reincornator 2021년 2월 16일
편집: reincornator 2021년 2월 16일
Thanks!
syms a b c
d=c*(a+b);
e=c*b+c*a;
j=a*b;
isAlways(e == d, 'Unknown', 'false')
isAlways(j == d, 'Unknown', 'false')

댓글을 달려면 로그인하십시오.

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by