fluidistic
Gold Member
- 3,928
- 272
Homework Statement
I must find the best fitting function of the form ax²+bx+c using least squares.
The points are (-1,6.1), (0,2.8), (1,2.2), (3,6) and (6,26.9).
2. Homework Equations + attempt at a solution
A\vec x= \vec b, I'm looking for \vec x =\begin {pmatrix} a \\ b \\ c \end {pmatrix}. I know that \vec b = \begin {pmatrix} 6.1 \\ 2.8 \\ 2.2 \\ 6 \\ 26.9 \end {pmatrix}.
With the use of some theory, the system I want to solve is equivalent to A^{T}A \vec x = A^{T} \vec b.
My matrix A is \begin {bmatrix} 1 & -1 & 1 \\ 0 & 0 & 1 \\ 1 & 1 & 1 \\ 9 & 3 & 1 \\ 36 & 6 & 1 \end {bmatrix}.
A^{T}A=\begin {bmatrix} 1379 & 243 & 47 \\ 243 & 47 & 9 \\ 47 & 9 & 5 \end {bmatrix}.
And A^{T}\vec b = \begin {bmatrix} 1030.7 \\ 175.5 \\ 44 \end {bmatrix}.
This gave me \vec x = \begin {bmatrix} 2.669598408 \\ -9.505782817 \\ 0.6247662773 \end {bmatrix}. Thus f(x) \approx 2.67 x^2-9.51 x +0.62.
I've plotted it in my calculator and it doesn't seem to fit well at all. My friend put these points in a program and he got a much better fitting (a \approx 3, b \approx -2, c \approx 1).
I've redone the algebra and I don't see my error(s).
I've followed the method of this page: http://tutorial.math.lamar.edu/Classes/LinAlg/LeastSquares.aspx.
I got right all problems involving a linear fit, but failed all other fits (exponentials, quadratic, etc.). What am I doing wrong?!
Another question that really matters to me is... why don't we solve Ax=b directly since we know both A and b, we would get 3 equations with 3 unknowns... why bother with the transpose of A?
Thank you very much for any help.