[SciPy-user] 3d interpolation

Fabian Braennstroem f.braennstroem at gmx.de
Tue Sep 19 01:49:00 EDT 2006


Hi Grant,

thanks for the small demo!

* Grant Edwards <grante at visi.com> wrote:
> On 2006-09-16, Fabian Braennstroem <f.braennstroem at gmx.de> wrote:
>
>>>> I would like to do some 3d interpolations. Is it possible
>>>> with scipy or should I use something different?
>>>
>>> I find that Scientific.Functions.LeastSquares.leastSquaresFit
>>> works well.
>>
>> Do you have a small working example?
>
> Here's something I just tossed together...
>
> ---------------------------------demo.py---------------------------------
> #!/usr/bin/python
> import Scientific.Functions.LeastSquares
> lsf = Scientific.Functions.LeastSquares.leastSquaresFit
>
> def m(c,p):
>     a,b,c,d,e = c
>     x,y = p
>     return a*x + b*x*x + c*y +d*y*y +e
>
> # data for surface  z = 1.2*x - 0.2*x*x -y + 0.1*y*y + 3
> #      [[x,y],z]
>
> d = [[[0.000000,0.000000],3.000000],
>      [[0.000000,1.000000],2.100000],
>      [[0.000000,2.000000],1.400000],
>      [[0.000000,3.000000],0.900000],
>      [[1.000000,0.000000],4.000000],
>      [[1.000000,1.000000],3.100000],
>      [[1.000000,2.000000],2.400000],
>      [[1.000000,3.000000],1.900000],
>      [[2.000000,0.000000],4.600000],
>      [[2.000000,1.000000],3.700000],
>      [[2.000000,2.000000],3.000000],
>      [[2.000000,3.000000],2.500000],
>      [[3.000000,0.000000],4.800000],
>      [[3.000000,1.000000],3.900000],
>      [[3.000000,2.000000],3.200000],
>      [[3.000000,3.000000],2.700000],
>      [[4.000000,0.000000],4.600000],
>      [[4.000000,1.000000],3.700000],
>      [[4.000000,2.000000],3.000000],
>      [[4.000000,3.000000],2.500000]]
>
>
> r = lsf(model=m, parameters=[0,0,0,0,0], data=d)
>
> print "coefficients",  r[0]
> print "chisquared",  r[1]
> ---------------------------------demo.py---------------------------------
>
>
> $ python demo.py
> coefficients [1.1999998068357483, -0.19999995420210845, -0.99999983832361761, 0.099999948513050232, 3.0000000498833987]
> chisquared 1.75763435818e-13

Greetings!
 Fabian




More information about the SciPy-User mailing list