Find Child Subexpressions of Symbolic Expression
4 次查看(过去 30 天)
显示 更早的评论
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!