The polynomial's degree should be # of points - 1
e.g. if there are 2 points given it should be a line.
I know I can solve this using a matrix
e.g. if there are 4 points:
the polynomial would be y = ax^3 + bx^2 + cx + d
and the matrix would 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 do this operation with the inputs being the points {x0,y0} to {xn,xn}?
Look into Jama http://math.nist.gov/javanumerics/jama/ in particular QRDecomposition class of it.
I am currently writing something very similar and I found this from Princeton's CIS program very helpful.
http://introcs.cs.princeton.edu/java/97data/MultipleLinearRegression.java.html
The only thing is from Jama it does not return an x intercept so you would have no d in your equation.
You could also do this in excel using the Data Analysis tool and click on regression which would then return statistics on your dataset and an equation which best fits your data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With