Implementing curve fit using least squares method in C ++

I am trying to write a C ++ function to perform curve fitting using the least squares method. Input parameters of this function are x

both y

1D array and n

. And this function finds the coefficients of the p(x)

degree polynomial n

that match the data p(x(i))

to y(i)

in the least squares sense. Therefore, the function returns a 1D array.

could you help me?

+1


a source to share


2 answers


Here's a basic method via MathWorld (a great resource). For C ++ code, refer to your local library and look at Numerical Recipes .



+2


a source


boost :: ublas should have what you need for algebra. In the past, you should define your chi-square function and minimize it.



For more specific answers, you will likely need to update your post with more specific questions.

0


a source







All Articles