Least-square method

Let us have the set of values yi, every one of which corresponds to any moment of time ti (i = 1, 2,…, N). We need to find dependency y = f(t) if the sum of squared divergences of points of curve from the appropriate point yi is the minimal in the class of approximating functions. That is

(1)  Σ(f(ti) - yi)2 à min

We will find the solution in the class of the linear functions (straight lines): y = at + b. Then the term (1) we can write as the following

Σ(a*ti +b - yi)2 à min

The necessary condition of the existence of minimum is the equality to zero of two partial derivatives on a and b accordingly:

Σ((a*ti +b - yi)*ti) =0

Σ(a*ti +b - yi) = 0

In designations

Σti2 = stt 

Σ(yi*ti) = syt

Σ(ti) = st

Σ(yi) = sy

Σb = bN               

the system can be rewritten as the following

astt + bst - syt = 0

ast +bN - sy = 0

Solving this system of two linear equations for a and b we will get

a = (sytN - syst)/(Nstt - stst)

b = (sttsy - sytst)/(Nstt - stst)