Least squares method with Calcpad #359
Proektsoftbg
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
This is how we can use the least squares method with Calcpad:
I prepared three examples: for fitting line, parabola and 5-th degree polynomial to a set of data points with coordinates x and y.
The purpose is to minimize the sum of the squares of the distanced from the points to the curve.
The result is obtained by solving the matrix equation: X·X^T·a = X·y via Cholesky decomposition, where the matrix X = [1 | x | x^2 | ... | x^n] for polynomial of degree n. This give us the coefficients vector a = [a_0; a_1; a_2; ...; a_n] of the polynomial P(x) = a_0 + a_1·x + a_2·x^2 + ... + a_n·x^n. Finally, we construct the polynomial function by the expession P(x) = a·[1; x; x^2; ...; x^n].
Here is the source code of the above example:
Least squares.zip
Beta Was this translation helpful? Give feedback.
All reactions