3
$\begingroup$

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

{a1,a2,a3}

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

Alex

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

1 Answer 1

3
$\begingroup$

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];
List@@Expr[x,y]

which gives you

{a1*E^((-2+x)^2+y^2),a2*E^((-0.3+x)^2+(0.6+y)^2),a3*E^((0.5+x)^2+(0.88+y)^2)}

Next we want to extract the coefficients

List@@Expr[x,y]/.p_*Exp[_]->p

which gives you

{a1, a2, a3}
$\endgroup$
2
  • 1
    $\begingroup$ List @@ Expr[x, y] /. Exp[_] :> 1 is slightly more efficient $\endgroup$
    – Bob Hanlon
    Commented Jun 1, 2020 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
    Commented Jun 1, 2020 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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