[Numpy-discussion] lsq problem

Tommy Grav tgrav@mac....
Wed Feb 14 21:29:58 CST 2007


On Feb 14, 2007, at 10:11 PM, Keith Goodman wrote:

> On 2/14/07, Tommy Grav <tgrav@mac.com> 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
>> function
>>
>> 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.

I actually butchered the function, as it should read a*exp(-pow(x,2)/ 
b)) - c.
(I do not need to fit the center as that has already been when creating
the x array :).

Cheers
    Tommy


More information about the Numpy-discussion mailing list