Sub МНК_лин1(x() As Double, y() As Double, a As Double, b As Double, n As Integer)
Dim Sxy As Double, Sx As Double, Sy As Double, Sx2 As Double, i As Integer
For i = 1 To n
Sxy = Sxy + x(i) * y(i)
Sx = Sx + x(i)
Sy = Sy + y(i)
Sx2 = Sx2 + x(i) * x(i)
Next i
b = n * Sx2 - Sx ^ 2
a = (n * Sxy - Sx * Sy) / b
b = (Sy * Sx2 - Sx * Sxy) / b
End Sub

Sub МНК_степ()
Const n = 13
Dim x(n) As Double, y(n) As Double, xx(n) As Double, yy(n) As Double, i As Integer, a As Double, _
b As Double, a1 As Double, b1 As Double, S1 As Double, S As Double
For i = 1 To n
x(i) = Cells(i, 1)
y(i) = Cells(i, 2)
xx(i) = Log(x(i)) / Log(10)
yy(i) = Log(y(i)) / Log(10)
Next i
МНК_лин1 xx, yy, a1, b1, n
МНК_лин1 x, y, a, b, n
For i = 1 To n
S = S + (y(i) - (a * x(i) + b)) ^ 2
Next i
S = Sqr(S)
Debug.Print a, b, S
b = a1
a = 10 ^ b1
For i = 1 To n
Cells(i, 4) = a * x(i) ^ b
Next i
For i = 1 To n
S1 = S1 + (y(i) - (a * x(i) ^ b)) ^ 2
Next i
S1 = Sqr(S1)
Debug.Print a, b, S1
End Sub