Strange behaviour of simplify

조회 수: 3 (최근 30일)
Maximilian Schönau
Maximilian Schönau 2020년 5월 4일
댓글: Star Strider 2020년 5월 4일
Hello, when solving a math Problem today i noticed a strange behaviour of simplify and I cannot explain myself what I did wrong. Basically I do have two terms and want to compare if they are equal, but Matlab returns false, altough they actually are. Is there a syntax thing I did false?
syms a b c t
f1 = sqrt((a^2+b^2+c^2)/3) / t;
f2 = sqrt(((a/t)^2+(b/t)^2+(c/t)^2)/3);
pretty(simplify(f1==f2))
Here you can see, that both expressions are equal, but Matlab returns false:
logical(simplify(f1==f2))

채택된 답변

Star Strider
Star Strider 2020년 5월 4일
use the isAlways function to compare symbolic expressions:
syms a b c t
f1 = sqrt((a^2+b^2+c^2)/3) / t;
f2 = sqrt(((a/t)^2+(b/t)^2+(c/t)^2)/3);
pretty(simplify(f1==f2, 'Steps',500))
equalityTest = isAlways(f1 == f2)
here:
equalityTest =
logical
0
and:
Warning: Unable to prove '(a^2/3 + b^2/3 + c^2/3)^(1/2)/t == (a^2/(3*t^2) + b^2/(3*t^2) +
c^2/(3*t^2))^(1/2)'.
.
  댓글 수: 2
Maximilian Schönau
Maximilian Schönau 2020년 5월 4일
Thank you so much, I needed that function!
As for the assumed equality it is totally my fault that i did not notice the difference, in my function I use only Values bigger than zero...
Star Strider
Star Strider 2020년 5월 4일
As always, my pleasure!
You can set conditions in the syms call, for example:
syms a b c t positive real
f1 = sqrt((a^2+b^2+c^2)/3) / t;
f2 = sqrt(((a/t)^2+(b/t)^2+(c/t)^2)/3);
pretty(simplify(f1==f2, 'Steps',500))
equalityTest = isAlways(f1 == f2)
however that does not change the ‘equalityTest’ result.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 5월 4일
they are not the same. think about negative t

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by