Curve Fitting: y F (X) Ax + B F (X E
Curve Fitting: y F (X) Ax + B F (X E
We have data points: (x0, y0), (x1, y1), . . . , (xn, yn). We want a line that lies close to these data points (without necessarily passing through them) and matches their trend. We approximate the data with the line:
y = f (x) = Ax + B so that
of ways: Maximum error: Average error:
f (xk ) = yk + Ek
where Ek is the error at the point (xk , yk ). We can measure the total error in a number
1 n ( f (xk ) yk )2 n k=0
1/2
y = f (x) = Ax + B
while minimizing the root mean square error E2( f ). As a result, we need to minimize:
E2 ( f )
k=1
( f (xk) yk
)2 =
k=1
2 ( Ax + B y ) k k
Note that E is a function of A and B. Minimizing E ( f ) requires looking for the places where E /A and E /B are zero.
N E = 2(Axk + B yk )xk = 0 A k=1 N E = 2(Axk + B yk ) = 0 B k =1
A A
k=1 N k=1
2+B xk
k=1
xk = xkyk
k=1 N k=1
xk + B N = yk
We can t other types of functions if we expect other types of trends in the data. For example, suppose you expect the data to follow a power law:
y = AxB
but you dont know either the coefcient A or the power B. Through the magic of logarithms, we can convert this problem into tting a line through the data (X , Y ) =
Y = BX + C and
General Fitting
Suppose you want to t your data will a collection of M linearly independent functions
j=1
c j f j (x)
N M 2
E (c1, c2, . . . , cM ) =
To nd the c j s, we need:
k=1
( f (xk) yk)2 =
E =0 c j
k=1
j=1
c j f j (xk)
yk
j = 1, 2, . . . , M
This gives:
j=1
k=1
fi(xk ) f j (xk ) c j =
k=1
fi(xk )yk
FT Fc = FT y
where
FN M =
...