I'm dealing with a sum of exponential functions with different exponents

Expr[x_, y_] = a1 Exp[(x - 2)^2 + y^2] + a2 Exp[(x - 0.3)^2 + (y + 0.6)^2] + a3 Exp[(x + 0.5) 2 + (y + 0.88)^2]

and I would like to extract the coeffecients to get a result like this


I'm new to mathematica, so I'm not sure about which function fits best to deal with that kind of problem. It seems like CoeffiecientList is only useful for polynomial expressions. In addition I would like to expand the solution to a sum of a thousand exponential function. I'm not sure about how to use Coefficient or Cases in the right way, since the exponent of the exponential summands changes.

Best regards


  • $\begingroup$ This works by turning the a1,a2,a3 into basis vectors: Expr[5, 9] /. Thread[{a1, a2, a3} -> IdentityMatrix[3]] $\endgroup$
    – flinty
    Jun 1 '20 at 20:54

First we want to make certain that Mathematica doesn't reorder your coefficients. To do that we turn your sum into a list

Expr[x_, y_]:=a1*Exp[(x-2)^2+y^2]+a2*Exp[(x-0.3)^2+(y+0.6)^2]+a3*Exp[(x+0.5)^2+(y+0.88)^2];

which gives you


Next we want to extract the coefficients


which gives you

{a1, a2, a3}
  • $\begingroup$ List @@ Expr[x, y] /. Exp[_] :> 1 is slightly more efficient $\endgroup$
    – Bob Hanlon
    Jun 1 '20 at 21:04
  • 1
    $\begingroup$ Please use your most complicated sum that you are actually using, not some contrived example you won't ever really use, and restart Mathematica each time so that caching won't make a mess of the results and test the two versions and use AbsoluteTiming and report how many milliseconds the more efficient method saved and report back here. Thank you. $\endgroup$
    – Bill
    Jun 1 '20 at 21:08

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.