get only addends of subexpression

1 Ansicht (letzte 30 Tage)
David Armendáriz
David Armendáriz am 15 Mär. 2018
Kommentiert: Walter Roberson am 15 Mär. 2018
Suppose I have a symbolic expression like this
syms x x0
f=(x-x0)^3
children(f)
[(x-x0),3]
I would like to get instead
[(x-x0)^3]
How can this be done?
  1 Kommentar
Steven Lord
Steven Lord am 15 Mär. 2018
Can you say a little more about your ultimate goal? Perhaps there's a way to do what you want without running a MuPAD expression via feval(symengine, ...).

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 15 Mär. 2018
You cannot do that with children().
You need to do something like,
feval(symengine, '(V) -> if testtype(V,"_plus") then [op(V)] else [V] end_if;', f)
  2 Kommentare
David Armendáriz
David Armendáriz am 15 Mär. 2018
Thanks, and is there any way to do the same but with multiplication? I mean, if I have
f=a*b*c*d
I would like to get
[a,b,c,d]
And when
f=a
then the output is
[a]
Walter Roberson
Walter Roberson am 15 Mär. 2018
Use _mult instead of _plus for that purpose.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MuPAD finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by