2
$\begingroup$

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

$\endgroup$
1
  • 1
    $\begingroup$ 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. $\endgroup$
    – Silvia
    Jun 25, 2013 at 17:12

3 Answers 3

1
$\begingroup$

You can use CoefficientArrays or CoefficientList for this.

$\endgroup$
1
$\begingroup$

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

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

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}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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