Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a large mathematica expression that looks roughly like

f = A1 Exp[a1 x] + A2 Exp[a2 x] + b1/x + b2/x^2 + c0 + c1 x + c2 x^2

where all the $A_n,a_n,b_n,c_n$ are symbolic constants.
how can I isolate the prefactor of x ? i.e some function that checks the pattern of $f$ and returns $c_1$ ?

share|improve this question
Hi Amir. Welcome to this site! You mentioned "I have a large mathematica expression ...", thus please post the Mathematica expression/code, not the LaTeX formula, so others can directly copy & paste it into Mathematica and test it. –  Silvia Jun 25 '13 at 17:12
Thanks Silvia! done –  Amir Jun 25 '13 at 22:27
add comment

3 Answers

You can use CoefficientArrays or CoefficientList for this.

share|improve this answer
add comment

Another possibility is the command Coefficient. For example

Coefficient[a Exp[d x] + b x + c x^2 + 1/x + 2/x, x]

gathers all the terms in x, returning b.Similarly,

    Coefficient[a Exp[d x] + b x + c x^2 + 1/x + 2/x, a]

gives Exp[d x].

share|improve this answer
Great ! this is what I was looking for :) –  Amir Jun 25 '13 at 22:28
add comment

You should use Mathematica' pattern like Times[p_, x] that works well in case your symbolic constant does contain x. Cases will extract all matches. Please, see the following example:

f := A1 E^(a1*x) + A1 E^(a1*x) + b1/x + b2/x^2 + c0 + (c1 + 9023/x - 23.2)*x + c2*x^2;
Cases[f, Times[p_, x] :> p]

The output is:

{-23.2 + c1 + 9023/x}
share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.