ALGLIB forum
It is currently Sat Jul 20, 2024 12:34 pm

All times are UTC

Forum rules

1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Help needed with polynomialfit
PostPosted: Thu May 26, 2011 6:21 pm 

Joined: Thu May 26, 2011 6:15 pm
Posts: 1
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 as I get with Excel. This is my 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?

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group