0% found this document useful (0 votes)
43 views

Curve Fitting: y F (X) Ax + B F (X E

1. The document discusses different methods for fitting a line to a set of data points to approximate the underlying trend, including least squares regression. 2. Least squares regression finds the best-fit line by minimizing the root mean square error between the actual data points and the predicted values of the line. 3. This results in a linear system that can be solved to determine the coefficients of the best-fit line that approximates the data as closely as possible.

Uploaded by

sofianina05
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Curve Fitting: y F (X) Ax + B F (X E

1. The document discusses different methods for fitting a line to a set of data points to approximate the underlying trend, including least squares regression. 2. Least squares regression finds the best-fit line by minimizing the root mean square error between the actual data points and the predicted values of the line. 3. This results in a linear system that can be solved to determine the coefficients of the best-fit line that approximates the data as closely as possible.

Uploaded by

sofianina05
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Curve Fitting

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

E( f ) = max | f (xk ) yk | E1( f ) = E2( f ) = | f (xk ) yk | n


k=0 0kn 1 n

Root mean square error:

1 n ( f (xk ) yk )2 n k=0

1/2

In practice, the root mean square error is most commonly used.

Least Squares (Best Fit) Line


Let (xk , yk ), k = 1, . . . , N be a collection of points. Approximate them with:

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

Theorem (Least squares line) y = Ax + B where


N x y 2 )A + ( N x )B = (N x k k=1 k k=1 k=1 k k (N NB = N k=1 xk )A + k=1 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 ) =

(ln xk , ln yk ): ln y = ln(A xB) = ln A + ln xB = B ln x + ln A


Substituting Y = ln y, X = ln x and C = ln A, we have:

Y = BX + C and

N X Y 2 )B + ( N X )C = (N X k k=1 k k=1 k=1 k k N Y (N X ) B + NC = k k=1 k=1 k

General Fitting
Suppose you want to t your data will a collection of M linearly independent functions

f j (x) (for example x j , sin( jx) or cos( jx)) so that: f (x) =

j=1

c j f j (x)
N M 2

Least squares requires that you minimize the error:

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

which yields M equations with M unknowns. In matrix form:

FT Fc = FT y
where

FN M =

f1(x1) f1(x2) f1(x3)


. . .

f2(x1) . . . f2(x2) . . . f2(x3) . . .


. . . ...

f1(xN ) f2(xN ) . . . ... ...


...

f1(x1) f1(x2) f1(x3) f2(x1) f2(x2) f2(x3) T FM N = . . . . . . . . . fM (x1) fM (x2) fM (x3)

...

c1 c = c2 . . . . . . cM fM (xN ) f1(xN ) y1 y2 f2(xN ) y= . . . . . . fM (xN ) yN

fM (x1) fM (x2) fM (x3)

You might also like