Least Squares Method
Least Squares Method
Least Squares Method
We want to find a parabola with a vertical axis that passes through the origin and is closest to the given data points in the least squares sense . The equation of a parabola with a vertical axis can be written as follows :
ya+bx+c
2
x
Given that the parabola passes through the origin, we have :
0a+b(0)+c
2
(0)
Which simplifies to :
c0
Now, our equation becomes :
ya+bx
2
x
We are given three points : , , and .
(-1,3)
(1,1)
(2,5)
Substituting these into the equation, we have three linear equations :
For :
(-1,3)
3a+b(-1)
2
(-1)
For :
(1,1)
1a+b(1)
2
(1)
For :
(2,5)
5a+b(2)
2
(2)
To minimize the least squares error, we can set up a matrix equation , where is the matrix of independent variables, is the vector of coefficients, and is the matrix of the dependent variable .
Axb
A
x
b
Let
A
, x
, andb
.
1 | -1 |
1 | 1 |
4 | 2 |
a |
b |
3 |
1 |
5 |
The matrix equation becomes :
1 | -1 |
1 | 1 |
4 | 2 |
a |
b |
3 |
1 |
5 |
You can solve this system of equations using Wolfram Mathematica’s LinearSolve function.
You can solve this system of equations using Wolfram Mathematica’s LinearSolve function.
In[]:=
(*Definethematrixofindependentvariablesandthevectorofdependentvariables*)A={{1,-1},{1,1},{4,2}};b={3,1,5};(*UsetheLinearSolvefunctiontosolvethesystemofequations*)x=LinearSolve[Transpose[A].A,Transpose[A].b](*Theresultisalistofcoefficients[a,b]*)
Out[]=
,-
20
11
12
11
Solving the problem using alternative Fredholm theorem
Solving the problem using alternative Fredholm theorem
The alternative Fredholm theorem states that a linear system has a solution if and only if is orthogonal to the null space of . In other words, if b0, then there is a solution to the system . Let' s check this condition :
Axb
b
T
A
T
A
T
A
1 | 1 | 4 |
-1 | 1 | 2 |
T
A
1 | 1 | 4 |
-1 | 1 | 2 |
3 |
1 |
5 |
24 |
8 |
Sinceb≠0,thesystemdoesnothaveasolution.However,wecanfindthebestapproximatesolution(theleastsquaressolution)usingthenormalequations:
T
A
Axb
T
A
1 | 1 | 4 |
-1 | 1 | 2 |
1 | -1 |
1 | 1 |
4 | 2 |
18 | 8 |
8 | 6 |
Now we solve the normal equation Axb :
T
A
T
A
18 | 8 |
8 | 6 |
a |
b |
24 |
8 |
Thus, we get a system of the form :
18a+8b248a+6b8
Now, solving the above system by the method of substitution, we find that and and the equation of the parabola is :
a
20
11
b-
12
11
y-
20
11
2
x
12
11
Here is how you can solve this using Mathematica:
Here is how you can solve this using Mathematica:
In[]:=
(*Definethematrixofindependentvariablesandthevectorofdependentvariables*)A={{1,-1},{1,1},{4,2}};b={3,1,5};(*Computethenormalequations*)normalA=Transpose[A].A;normalb=Transpose[A].b;(*Solvethenormalequations*)solution=LinearSolve[normalA,normalb](*Theresultisalistofcoefficients[a,b]*)
Out[]=
,-
20
11
12
11