From: Jean-Baptiste C. <Jea...@de...> - 2004-03-21 19:50:32
|
S=E6l ! Thanks for the tip, but I do not want to use the lagrangian: I want many sm= all 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)=3Dax*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)=3DY0=3Da*X0*X0+b*X0+c f(X1)=3DY1=3Da*X1*X1+b*X1+c f'(X0)=3DZ0=3D 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 hav= e 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" <ga...@em...> wrote: > First, let me say, I don't know if there is code to do exactly what you w= ant but here are my thoughts. > It sounds to me like you're asking for Lagrange polynomial fitting routin= es. Googling for "lagrange polynomial python" does return some code here: <= http://www.stanford.edu/~sturdza/akimamod/akimamod.py> > Another possibility is the spline fitting routines in Scipy (scipy.interp= olate). 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 func= tions 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 :-( I= think they were SWIG wrappers for a C library. > Also, look at this: > <http://www.scipy.org/site_content/remap?rmurl=3Dhttp%3A//www.scipy.net/p= ipermail/scipy-user/2003-August/001864.html> > HTH, > regards, > Gary >=20 > ----- Original Message ----- > From: Jean-Baptiste Cazier <Jea...@de...> > Date: Fri, 19 Mar 2004 11:49:21 +0000 > To: "Gary Ruben" <ga...@em...>, jdh...@ni... > Subject: Re: [Matplotlib-users] Polyfit >=20 > >=20 > > Thanks to both of you. It worked just fine > >=20 > > I will push my luck and ask if any of you knows of a module to fit a pi= ecewise polynomial to a list of (X,Y) points. > > something like=20 > > p=3Dpiece-wiseFit([1,2,5,7,8],[3,4,2,5,5],2)=20 > > would return [[A0,B0,C0],[A1,B1,C1}[A2,B2,C2},[A3,B3,C3]}, coefficients= for the 4 polynoms=20 > > A0+B0.X+C0.X.X > > A1+B1.X+C1.X.X > > A2+B2.X+C2.X.X > > A3+B2.X+C3.X.X > >=20 > > This is a classic and I expect the code to be written somewhere, eventh= ough I could not find it even when I "Feel lucky" with Google. > <snip> > --=20 > ___________________________________________________________ > Sign-up for Ads Free at Mail.com > http://promo.mail.com/adsfreejump.htm >=20 --=20 ----------------------------- Jea...@de... Department of Statistics deCODE genetics Sturlugata,8 570 2993 101 Reykjav=EDk |