Solving Linear Equations(1)
Solving Linear Equations(1)
Dr Minh Nguyen1
Outline
1 Fitting lines
Fitting lines
A set of data. How to find a straight line that is "best fit" the set?
Fitting lines
Linear equations
y = ax + b.
We will have to determine the best a, b to fit the set of the data.
Solving equations
Solving equations
By switching a, b to x, y we actually have to solve x, y from the
system
a1 = xb1 + y
a2 = xb2 + y
······
aN = xbN + y .
Optimal solutions
E(x, y ) := |a1 −(xb1 +y )|2 +|a2 −(xb2 +y )|2 +· · ·+|aN −(xbN +y )|2 .
N
X
E(x, y ) = aJ2 − 2aj (xbj + y ) + (xbj + y )2
j=1
N
X
= aJ2 − 2aj bj x − 2aj y + x 2 bj2 + 2bj xy + y 2
j=1
N
X
= bj2 x 2 + 2bj xy + y 2 − 2aj bj x − 2aj y + aJ2
j=1
N
X XN N
X
= bj2 x 2 + 2 bj xy + Ny 2 − 2 aj bj x
j=1 j=1 j=1
N
X N
X
− 2 aj y + aj2 .
Fitting lines
1 x x
E(x, y ) = (x, y )A −B + c,
2 y y
where
N N N
" P #
2 N 2 2
PN
b b
j=1 j
X X X
A := Pj=1 j
, B := 2 a b
j j , 2 a j
, c = aj2 .
2 N b
j=1 j 2N j=1 j=1 j=1
x
Hession(E) = A, ∇E = A − BT .
y
Fitting lines
A General problem
Ax = b,
If you use Maple with package Linear Algebra you can compute
x∗ using some command lines. If not, you can use gradient
method with fixed step size small enough.
Fitting lines
A General problem
Ax = b,