forum.alglib.net
http://forum.alglib.net/

Help needed with polynomialfit
http://forum.alglib.net/viewtopic.php?f=2&t=366
Page 1 of 1

Author:  Espectro [ Thu May 26, 2011 6:21 pm ]
Post subject:  Help needed with polynomialfit

Hi there

Very nice work on this package!

I am trying to make a straight line fitting (a*x + b) on some data-points I have, but I am having some problems obtaining similar results using alglib.net as I get with Excel. This is my code:
Code:
double[] x = new double[] { -13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,160,17 };
            double[] y = new double[] { 3.94117647058823, 3.72727272727272,2.8695652173913,3.34482758620689,3.06896551724137,3.66666666666666,2.92307692307692,3.03030303030303,2.93333333333333,2.60344827586206,2.71111111111111,2,2.14084507042253,2.25757575757575,2.5,1.95121951219512,2.22807017543859,1.98630136986301,1.94520547945205,1.7012987012987,1.68055555555555,1.86301369863013,1.56060606060606,1.4,1.61538461538461,1.37254901960784,1.41176470588235,1.38095238095238,1.45,1.33333333333333,1.378378378378 };
            int m = 2;
            double t = 2;
            int info;
            alglib.barycentricinterpolant p;
            alglib.polynomialfitreport rep;
            double v;
            alglib.polynomialfit(x, y, m, out info, out p, out rep);
            v = alglib.barycentriccalc(p, t);
            double[] a2;
            alglib.polynomialbar2pow(p, out a2);

The result is this:

[0] 2.3410245814871029 double
[1] -0.012596899769274472 double (a*x + b)

Which translates to:
-0.012596899769274472x + 2.3410245814871029

But using the same samples in excel I archive the following numbers:
-0.0814x + 2.42

What am I doing wrong here?
Thanks

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/