0
|
4282 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
GROUPS:

# Decompose Expression into Segments

Posted 10 years ago
 Say I have an expressiontest = 3 x1^2 - 2 x3^-3and I would like to decompose the expression into {3 x1^2, -(2/x3^3)} I can do that by using List @@ test on Mathematica.However, the problem I face is that when the expression is test = x1^2, i get {x1, 2} and for test = (3 x1^2) i get {3, x1^2} instead of {x1^2} and {3x1^2} respectively.The added information I have is the list of variables. For example, if test = x1^2 I have the list of variables, which is {x1}. And for test = 3 x1^2 - 2 x3^-3, I have {x1,x3}Is there any other way to get what I want?Thanks
2 Replies
Sort By:
Posted 10 years ago
 Are you considering polynomials only? Then would MonomialList be enough?MonomialList[a x^2 + b x y + c y^2, {x, y}]Out[]= {a x^2, b x y, c y^2}
Posted 10 years ago
 I'm guessing you want to divide up "terms" and not divide up "factors", i.e, divide up + and - but not * and / and ^ In:= 3 x1^2 - 2 x3^-3 /. Plus -> List  Out= {3 x1^2, -(2/x3^3)}  In:= x1^2 /. Plus -> List  Out= x1^2  In:= 3 x1^2 /. Plus -> ListOut= 3 x1^2But if you start having even more complicated expressions then you might run into trouble with things like thisIn:= x^(2 a + b) /. Plus -> ListOut= {x^(2 a), x^b}and it isn't clear whether that is what you would want or not.If that is not what you would want to happen then you might consider substituting for Plus only at the topmost level.