[Numpy-discussion] lsq problem
Wed Feb 14 21:11:59 CST 2007
On 2/14/07, Tommy Grav <firstname.lastname@example.org> wrote:
> I need to fit a gaussian profile to a set of points and would like to
> use scipy (or numpy) to
> do the least square fitting if possible. I am however unsure if the
> proper routines are
> available, so I thought I would ask to get some hints to get going in
> the right direction.
> The input are two 1-dimensional arrays x and flux, together with a
> def Gaussian(a,b,c,x1):
> return a*exp(-(pow(x1,2)/pow(c,2))) - c
> I would like to find the values of (a,b,c), such that the difference
> between the gaussian
> and fluxes are minimalized.
You left b out of your function: a*exp(-power((x - b),2) / c).
If it is a one-off example you can always use brute force---just search a grid:
for a in as:
for b in bs:
for c in cs:
But if you have a lot of data or you need to do many fits I bet scipy
has what you need.
More information about the Numpy-discussion