How do i do the reverse from expand function ?

31 ビュー (過去 30 日間)
tomer gigi
tomer gigi 2021 年 11 月 12 日
編集済み: Stephen23 2024 年 3 月 23 日 17:41
I have an expression lets say
a^2_2*a*b+b^2+b
and i want to simplify the expression to get
(a+b)^2+b
what is the proper way of doing this ?

回答 (1 件)

Chidvi Modala
Chidvi Modala 2021 年 11 月 19 日
Hi Tomer,
In general, you may use simplify(expr) function to perform algebraic simplification of expr. But simplify currently has some known issue with the simplification of sums. It cannot simplify your entire expression "a^2+2*a*b+b^2+b", but it can simplify "a^2+2*a*b+b^2" to "(a+b)^2". You may use the following example as a workaround.
syms a b;
simplify(expand(a^2+2*a*b+b^2)) + b
  3 件のコメント
John D'Errico
John D'Errico 2024 年 3 月 23 日 15:40
No. Simplify still does not see how to return a partially factored result. I would have tried this:
syms a b
expr = a^2+2*a*b+b^2+b;
simplify(expr,steps = 1000,All = true)
ans = 
as the standard way to solve it using simplfy, to see if it would find an alternate form.
But as you can see, it finds no "simpler" way to write that expression. The above was done using the Matlab version in Answers of R2023b.
Stephen23
Stephen23 2024 年 3 月 23 日 17:41
編集済み: Stephen23 2024 年 3 月 23 日 17:41
It all depends on what metric you are using to define the term "simpler". According to some metrics you might come up with, using the parentheses could be considered more complex:
Expecting a computer to read minds and replicate nebulous human concepts... perhaps we need to involve some AI engine here: proposed new AI-based command SHOWMETHISLIKEIWOULDSEEITINATEXTBOOK().

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

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by