Find Child Subexpressions of Symbolic Expression
8 ビュー (過去 30 日間)
古いコメントを表示
Erivelton Gualter
2019 年 4 月 12 日
コメント済み: Walter Roberson
2019 年 4 月 14 日
I believe the function children might have a problem. Acording to the documentation it returns a cell array containing the child subexpressions of each expression in A.
For example:
syms x y
children(x^2 + x*y + y^2)
It will return:
[ x*y, x^2, y^2]
However, for the following:
children(x*y)
it return:
[ x, y]
I believe it should return:
x*y
Is it a bug ? Or am I missing something?
0 件のコメント
採用された回答
Walter Roberson
2019 年 4 月 12 日
You are missing something.
x^2 + x*y + y^2
is internally
_plus(_power(x, 2), _mult(x, y), _power(y,2))
children() removes the outer layer call and returns its arguments, giving back what would be internally
matrix([_power(x, 2), _mult(x, y), _power(y,2)])
which the interface translates back to
[x^2, x*y, y^2]
And likewise,
x*y
is internally
_multi(x,y)
children() removes the outer layer call and returns its arguments, giving back what would be internally
matrix([x, y])
which the interface translates back to
[x, y]
The children() call does not just find operands of additions and declare anything non-addition to be indivisible: it removes the outermost operation, no matter what it is. For example, children(sin(x*pi/2)) would remove the sin() giving you back x*pi/2
4 件のコメント
Walter Roberson
2019 年 4 月 14 日
In R2018b the only way to proceed is to write MuPAD code that you evaluate using evalin(symengine) or feval(symengine) . The MuPAD code would have to know how expressions are internally represented.
R2019a added additional ways of examining sub-expressions without having to use MuPAD code.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!