Polyfit

First, let me say, I don't know if there is code to do exactly what you want but here are my thoughts.
It sounds to me like you're asking for Lagrange polynomial fitting routines. Googling for "lagrange polynomial python" does return some code here: <http://www.stanford.edu/~sturdza/akimamod/akimamod.py&gt;
Another possibility is the spline fitting routines in Scipy (scipy.interpolate). These may be appropriate if what you're really after is just a way to fit smooth functions through points. I've used the splrep and splev functions there successfully to fit spline functions through points. When I was looking for curve fitting routines recently, I also came across some more generalized curve fitting modules for Python but I can't recall where :frowning: I think they were SWIG wrappers for a C library.
Also, look at this:
<http://www.scipy.org/site_content/remap?rmurl=http%3A//www.scipy.net/pipermail/scipy-user/2003-August/001864.html&gt;
HTH,
regards,
Gary

···

----- Original Message -----
From: Jean-Baptiste Cazier <Jean-Baptiste.cazier@...15...>
Date: Fri, 19 Mar 2004 11:49:21 +0000
To: "Gary Ruben" <gazzar@...25...>, jdhunter@...8...
Subject: Re: [Matplotlib-users] Polyfit

Thanks to both of you. It worked just fine

I will push my luck and ask if any of you knows of a module to fit a piecewise polynomial to a list of (X,Y) points.
something like
p=piece-wiseFit([1,2,5,7,8],[3,4,2,5,5],2)
would return [[A0,B0,C0],[A1,B1,C1}[A2,B2,C2},[A3,B3,C3]}, coefficients for the 4 polynoms
A0+B0.X+C0.X.X
A1+B1.X+C1.X.X
A2+B2.X+C2.X.X
A3+B2.X+C3.X.X

This is a classic and I expect the code to be written somewhere, eventhough I could not find it even when I "Feel lucky" with Google.

<snip>
--
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm

Sæl !

Thanks for the tip, but I do not want to use the lagrangian: I want many small polynoms, not 1

What I want to do is very typical in Finite Element Method eventhough this is not the case here.
I just want to define many small polynoms between consecutives points.
Each one is stsifying the continuity of the value as well as the derivative
if I define my function as f(x)=ax*x+bx+c
At my points (X0,Y0) (X1,Y1) as well at teh derivative a X0 to be Z0 I get the follwoing
f(X0)=Y0=a*X0*X0+b*X0+c
f(X1)=Y1=a*X1*X1+b*X1+c
f'(X0)=Z0= 2aX0+b

After small manipulkation I can directly infere a,b,c

This is a very simple but useful routine that I was hoping people would have already written
Actually it is much smoother with a cubic polynomial, but it is a bit more complicated to implement

Thanks anyway

Jean-Baptiste

···

On Fri, 19 Mar 2004 23:49:28 +1000 "Gary Ruben" <gazzar@...25...> wrote:

First, let me say, I don't know if there is code to do exactly what you want but here are my thoughts.
It sounds to me like you're asking for Lagrange polynomial fitting routines. Googling for "lagrange polynomial python" does return some code here: <http://www.stanford.edu/~sturdza/akimamod/akimamod.py&gt;
Another possibility is the spline fitting routines in Scipy (scipy.interpolate). These may be appropriate if what you're really after is just a way to fit smooth functions through points. I've used the splrep and splev functions there successfully to fit spline functions through points. When I was looking for curve fitting routines recently, I also came across some more generalized curve fitting modules for Python but I can't recall where :frowning: I think they were SWIG wrappers for a C library.
Also, look at this:
<http://www.scipy.org/site_content/remap?rmurl=http%3A//www.scipy.net/pipermail/scipy-user/2003-August/001864.html&gt;
HTH,
regards,
Gary

----- Original Message -----
From: Jean-Baptiste Cazier <Jean-Baptiste.cazier@...15...>
Date: Fri, 19 Mar 2004 11:49:21 +0000
To: "Gary Ruben" <gazzar@...25...>, jdhunter@...8...
Subject: Re: [Matplotlib-users] Polyfit

>
> Thanks to both of you. It worked just fine
>
> I will push my luck and ask if any of you knows of a module to fit a piecewise polynomial to a list of (X,Y) points.
> something like
> p=piece-wiseFit([1,2,5,7,8],[3,4,2,5,5],2)
> would return [[A0,B0,C0],[A1,B1,C1}[A2,B2,C2},[A3,B3,C3]}, coefficients for the 4 polynoms
> A0+B0.X+C0.X.X
> A1+B1.X+C1.X.X
> A2+B2.X+C2.X.X
> A3+B2.X+C3.X.X
>
> This is a classic and I expect the code to be written somewhere, eventhough I could not find it even when I "Feel lucky" with Google.
<snip>
--
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm

--
-----------------------------
Jean-Baptiste.Cazier@...15...

Department of Statistics
deCODE genetics Sturlugata,8
570 2993 101 Reykjavík