Least Square
Least Square
ei abs( a0 a1 xi yi )
n n
Let S ei2 ( a0 a1 xi yi )2
i 1 i 1
S n
2( a0 a1 xi yi ) 0
a0 i 1 … (1) and
S n
2 xi ( a0 a1 xi yi ) 0
a1 i 1 … (2)
na0 a1 xi yi
From (1), we get i i … (3) and
a0 xi a1 xi2 xi yi
From (2), we get i i i …(4)
n xi yi xi yi
a1
n xi2 xi 2
yi a xi
Given this, we obtain a0
n
1
n
How well does the line y a0 a1x cover the data?
This is given by the correlation coefficient where
cov( x , y )
( x, y )
x y
n xy x y 2
where ( x , y )
n x 2 x 2 n y 2 y 2
The correlation coefficient is bounded: 1 1.
A good fit implies absolute value of is closer to 1.
a X x Y log y y ae bx
b. X log x Y log y y ax b
c. X log x Y y
y log ax b 2
d. X x2 Y ey
e y a bx 2
…
>> a
a=
1 2
2 4
3 5
4 6
5 9
6 3
7 12
8 15
9 14
>> x=a(:,1)'
x=
1 2 3 4 5 6 7 8 9
>> y=a(:,2)'
y=
2 4 5 6 9 3 12 15 14
>> pcoeff=polyfit(x,y,1)
pcoeff =
1.5333 0.1111
>>
>> pcoeff=polyfit(x,y,2)
pcoeff =
>> r=corrcoef(a)
r=
1.0000 0.8582
0.8582 1.0000
>>