I've been hunting around for examples using the sum of least squares + partial derivative method to fit a polynomial to a set of points but am completely stuck. All the examples I've found involve matrices, but I am unfamiliar with how to use matrices.
Full disclosure, this is a homework problem for a multivariable calculus course. Here's what I've tried:
Points $(-2,4)$, $(-1,2)$, $(0,1)$, $(1,1)$, and $(2,2)$ so n=5
My method: $$f(a,b,c) = \sum{(y_i-(ax_i^2+bx_i+c))^2}$$ $$f(a,b,c) = \sum{y_i^2}-2a\sum{y_ix_i^2}=2b\sum{y_ix_i}-2c\sum{y_i}+a^2\sum{x_i^4}+2ab\sum{x_i^3}+2ac\sum{2_i^2}+2bc\sum{x_i}+b^2\sum{x_i^2}+5c^2$$
Find the partial derivatives for a, b, c and set to 0 $$f_a = -2\sum{y_ix_i^2}+2a\sum{x_i^4}+2b\sum{x_i^3}+2c\sum{x_i^2}$$ $$f_b = -2\sum{y_ix_i}+2a\sum{x_i^3}+2c\sum{x_i}+2b\sum{x_i^2}$$ $$f_c = -2\sum{y_i}+2a\sum{x_i^2}+2b\sum{x_i}+10c$$
Calculate all the sums: $$\sum{x_i^4} = 34$$ $$\sum{x_i^3} = 0$$ $$\sum{x_i^2} = 10$$ $$\sum{x_i} = 0$$ $$\sum{y_i} = 10$$ $$\sum{y_ix_i} = -5$$ $$\sum{y_ix_i^2} = 27$$
But when I plug the sums in and set the partial deriatives to 0, I get the wrong answer: $$68a+20c = 54$$ $$20b = -10$$ $$20a = 20$$
Which gives: $$y = x^2-\frac{1}{2}x - \frac{7}{10}$$
I checked over the equations and I think they look right...but clearly they're not :/
Thank you!
eep this was a simple algebra error!
Going to leave this up just in case anyone in the future is hunting around for an example of a polynomial fit using least squares without matrices.