Re: Polynomial Fit Program
- From: Phil Hobbs <pcdhSpamMeSenseless@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 07 Dec 2007 15:22:59 -0500
user923005 wrote:
On Dec 6, 10:22 am, Phil Hobbs
<pcdhSpamMeSensel...@xxxxxxxxxxxxxxxxxx> wrote:
Helmut Jarausch wrote:Thomas Smid wrote:This works okay as long as you don't try to go to very high order--thatHi,I don't know if it helps, but free "Matrix Packages" like Octave or Scilab
Does anybody know an open source code for a one dimensional polynomial
(n-th order) least squares fit program (preferably C++ or Fortran)?
Something similar to the Java applet under
http://www3.sympatico.ca/mcomeau/webpublic/javapage/reg/reg.htmwould
do, but I need the source code, as I need to modify it to perform a
weighted fit (if this isn't built in already). Alternatively, if
somebody knows the contact details of the author of this particular
Java applet (Michel Comeau), it might help me as well.
have it built in.
What you really need is a Q-R-decomposition from any linear algebra
package in C++.
In the simplest case (polynomials of moderate degree), if your data is
contained
in the two column vectors x and y, build the matrix
A=[ones(x),x,x.^2,x.^3] // for a polynomial of degree 3
This is Matlab/Scilab/Octave jargon :
ones(x) : a column vector of as many ones as x has components
x.^n : (note the dot in front of ^) a column vector which has
x_i^n as i-th component
Now solve the least squares problem A*c ~ y and c contains the
coefficients
of the polynomial (lowest first).
If you have weights, e.g. w_i, then first formally
build the diagonal matrix W= diag(w_1,...) and
solve the least squares problem W*A*c ~ W*y
In practice this is done by multiplying the i-th row of A and the
i-th component of y by w_i.
As you can see, if you have a standard (i.e. non weighted) least squares
solver you don't need to modify it.
matrix [x_i^j] is a subset of the Hilbert matrix, which is very very ill
conditioned for large orders.
Using an extended precision package, you can exactly invert a fairly
large Hilbert matrix. Using MIRACL, I just exactly inverted a Hilbert
matrix of dimention 199.
http://www.shamus.ie/
I believe that it's possible to do so, all right, but the same ill-conditioning will affect the polynomial evaluation from coefficients, so doing it that way means that essentially all subsequent uses of the fit polynomial also have do be done in multiple precision.
A Chebyshev fit would probably work in 32-bit floats.
Cheers,
Phil Hobbs
.
- References:
- Polynomial Fit Program
- From: Thomas Smid
- Re: Polynomial Fit Program
- From: Helmut Jarausch
- Re: Polynomial Fit Program
- From: Phil Hobbs
- Re: Polynomial Fit Program
- From: user923005
- Polynomial Fit Program
- Prev by Date: language question about numerical PDE
- Next by Date: Re: language question about numerical PDE
- Previous by thread: Re: Polynomial Fit Program
- Next by thread: Re: Polynomial Fit Program
- Index(es):
Relevant Pages
|