# Isolating a prefactor in an analytical expression

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$ ?

• 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. Jun 25, 2013 at 17:12

You can use CoefficientArrays or CoefficientList for this.

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].

• Great ! this is what I was looking for :)
– Amir
Jun 25, 2013 at 22:28

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}