Is it possible to simplify symbolic expressions with known relations

1 回表示 (過去 30 日間)
rooo000
rooo000 2019 年 3 月 18 日
コメント済み: Star Strider 2019 年 3 月 18 日
Say I have some arbitrary symbolic expressions
syms x1 x2
% x1*x2 == 1
a = x1*x2 + x1*x2;
b = 2*a
If it is known that x1 * x2 == 1 is it possible to have matlab actively simplify based off of that relation so that b returns the answer 4 without the use of subs?

採用された回答

Star Strider
Star Strider 2019 年 3 月 18 日
I assume (link) it would!
syms x1 x2
assume(x1*x2 == 1)
a = x1*x2 + x1*x2;
b = 2*a
producing:
b =
4*x1*x2
  2 件のコメント
rooo000
rooo000 2019 年 3 月 18 日
Haha! Very much appreciated thank you.
Star Strider
Star Strider 2019 年 3 月 18 日
As always, my pleasure!

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

その他の回答 (1 件)

Stephan
Stephan 2019 年 3 月 18 日
編集済み: Stephan 2019 年 3 月 18 日
Hi,
use assume - like Star Strider suggested and additionally use simplify to get the desired result;
syms x1 x2
assume(x1*x2 == 1)
a = x1*x2 + x1*x2;
b = 2*a;
b = simplify(b)
result:
b =
4

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by