I have a function that is a summation of several Gaussians. Working with a 1D Gaussian here, there are 3 variables for each Gaussian: A
, mx
, and sigma
:
$A \exp \left ( - \frac{\left ( x - mx \right )^{2}}{2 \times sigma^{2}} \right )$
A*Exp[-((x - mx)^2/(2 sigma^2))]
The number of Gaussians in the final function will be vary each time the function is called, so my question is: What is the best way to define a function in Mathematica that can handle this variation, rather than hard-coding each Gaussian?
I was thinking along the lines of providing a list of {A,mx,sigma}
to the function, so that if I want one Gaussian, I provide:
f[{{A,mx,sigma}}]
And if I want two Gaussians, I provide
f[{{A,mx,sigma},{A2,mx2,sigma2}}]
which would give:
A*Exp[-((x-mx)^2/(2sigma^2))] + A2*Exp[-((x-mx2)^2/(2sigma2^2))]
and so on.
But I'm not at all sure how to design the function f[]
to do this efficiently (for example, can it be done without a For[]
loop? Can it be compiled in future if necessary?).
Any help much appreciated - I did several searches on here and couldn't find anything, but I realise that might be because I'm not sure how to define my problem succinctly, so apologies if it has been asked before and I've missed it.