0

I have a (sampled) set of uncalibrated values (x) coming from a device and a set of what they should be (y). I'm looking to find/estimate the cubic polynomial y=ax^3 + bx^2 + cx + d that maps any x to y.

So I think what I need to do is Polynomial Regression first and then find its inverse, but I'm not so sure; and I wonder whether there is a better solution like least squares.

I would appreciate a nudge in the right direction and/or any links to a math library that would be of use.

Meirion Hughes
  • 24,994
  • 12
  • 71
  • 122
  • I think I got muddled up and overcomplicated it; I think I just need Polynomial Regression with the given set of [x, y]. – Meirion Hughes Feb 18 '13 at 15:48
  • Similar [question](http://stackoverflow.com/questions/382186/fitting-polynomials-to-data) with a lot of references. – Ante Mar 05 '13 at 08:38

2 Answers2

0

Have you checked Langrange Interpolation? It is about the polynomial approximation of a given function.

You can stop the approximation on a given degree of the polynomial (let's say the 3rd degree) on a proper range of the indipendent variable.

Refs:

Community
  • 1
  • 1
Alberto De Caro
  • 5,147
  • 9
  • 47
  • 73
0

Looks like its just Polynomial Regression; I just need to feed in the raw (x) values and the expected values (y).

Code from Rosetta Code, that uses Math.Net Numerics

using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Double.Factorization;
public static class PolyRegression
{
    public static double[] Polyfit(double[] x, double[] y, int degree)
    {
        // Vandermonde matrix
        var v = new DenseMatrix(x.Length, degree + 1);
        for (int i = 0; i < v.RowCount; i++)
            for (int j = 0; j <= degree; j++) v[i, j] = Math.Pow(x[i], j);
        var yv = new DenseVector(y).ToColumnMatrix();
        QR qr = v.QR();
        // Math.Net doesn't have an "economy" QR, so:
        // cut R short to square upper triangle, then recompute Q
        var r = qr.R.SubMatrix(0, degree + 1, 0, degree + 1);
        var q = v.Multiply(r.Inverse());
        var p = r.Inverse().Multiply(q.TransposeThisAndMultiply(yv));
        return p.Column(0).ToArray();
    }
}
Meirion Hughes
  • 24,994
  • 12
  • 71
  • 122