Why does the distributive property fail when comparing expressions?

As a simplified example, I'm trying to compare whether two expressions are equal, where they are simply written differently. But
syms a x y;
logical((x+y)*a == x*a + y*a)
returns false, and everything else that assumes distributivity of + and *. Is there some other function that will help me, or some explanation why this happens?

1 件のコメント

Stephen Prunty
Stephen Prunty 2018 年 4 月 18 日
Ah, just found out apparently using simplify on both sides of the equals returns true.

サインインしてコメントする。

回答 (1 件)

Star Strider
Star Strider 2018 年 4 月 18 日

0 投票

To get logical results with symbolic expressions, use the isAlways (link) function.

syms a x y;
TF = isAlways((x+y)*a == x*a + y*a)
TF =
    logical
     1

カテゴリ

質問済み:

2018 年 4 月 18 日

回答済み:

2018 年 4 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by