Sub МНК_кв()
Const n = 13, m = (n + 1) / 2, H1 = n * (n ^ 2 - 1) / 12, H2 = n * (n ^ 2 - 1) * (n ^ 2 - 4) / 180
Dim x(1 To n) As Double, y(1 To n) As Double, a As Double, b As Double, c As Double, i As Integer, _
Sy As Double, Sym2 As Double, Sym As Double, h As Double, xs As Double, yi As Double, s As Double
For i = 1 To n
x(i) = Cells(i, 1)
y(i) = Cells(i, 2)
Sy = Sy + y(i)
Sym2 = Sym2 + y(i) * (i - m) ^ 2
Sym = Sym + y(i) * (i - m)
Next i
h = x(2) - x(1)
xs = (x(1) + x(n)) / 2
a = 1 / (3 * H2) * (3 * Sym2 - (n ^ 2 - 1) / 4 * Sy)
b = 1 / H1 * Sym
c = Sy / n - H1 / n * a
For i = 1 To n
yi = a * ((x(i) - xs) / h) ^ 2 + b * (x(i) - xs) / h + c
s = s + (y(i) - yi) ^ 2
Cells(i, 5) = yi
Next i
s = Sqr(s)
Debug.Print a, b, c, s
End Sub