Java library for point set polynomial estimation

The degree of the polynomial should be # of points - 1 for example. if there are 2 points, it should be a line.

I know that I can solve this using a matrix

eg. if there are 4 points:
the polynomial will be y = ax^3 + bx^2 + cx + d , and the matrix will be

 | y0 | | x0^3 x0^2 x0 1 | | a | | y1 | = | x1^3 x1^2 x1 1 | x | b | | y2 | | x2^3 x2^2 x2 1 | | c | | y3 | | x3^3 x3^2 x3 1 | | d | 

and I can solve for a, b, c, d. Is there a library that can perform this operation, and the inputs are points {x0, y0} to {xn, xn}?

+5
source share
1 answer

Look at Jama http://math.nist.gov/javanumerics/jama/ , specifically the QRDecomposition class.

I am currently writing something very similar, and I found this from the Princeton CIS program very useful.

http://introcs.cs.princeton.edu/java/97data/MultipleLinearRegression.java.html

The only thing is from Jama, it does not return an x-interception, so you will not have d in your equation.

You can also do this in Excel using a data analysis tool and click on a regression, which then returns the statistics for your data set and the equation that best matches your data.

+3
source

All Articles