Reputation: 77991
In Mathematica
if I have a symbolic algebra equation, how can I get the factor which is multiplied by a specific term?
I mean, say, as the result of some calculation I get a symbolic equation a x^2 + b x + c y
, and say I am interested in whatever is multiplied by x^2
(i.e. a
in here). What statement should I write such that if applied to a x^2 + b x + c y
returns a
.
(note that in the example there is a b x
term so I cannot use derivatives to extract the factor)
Upvotes: 1
Views: 2484
Reputation: 733
I believe what you are asking for is how to extract a coefficient. For polynomial expressions you can use something like this:
In[1]:= Coefficient[(x+y)^3, xy^2]
Out[1]:= 3
More generally, if you want to get all the coefficients, you can use CoefficientList
like so:
In[1]:= f = a x^2 + b x + c;
CoefficientList[f, x]
Out[2]= {c, b, a}
Upvotes: 6