Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function int_kw_popr(zakres_X As Range, zakres_Y As Range, x0) As Single
- Dim x2w(1 To 3, 1 To 3) As Single
- Dim x(1 To 3) As Single
- Dim y(1 To 3) As Single
- Dim i As Integer, n As Integer, j As Integer
- Dim bmin As Single
- n = zakres_X.Cells.Count
- bmin = WorksheetFunction.Large(zakres_X, 1) + WorksheetFunction.Large(zakres_X, 2) + WorksheetFunction.Large(zakres_X, 3)
- For i = 1 To n - 2
- If Abs(zakres_X.Cells(i) + zakres_X.Cells(i + 1) + zakres_X.Cells(i + 2) - 3 * x0) < bmin Then
- bmin = Abs(zakres_X.Cells(i) + zakres_X.Cells(i + 1) + zakres_X.Cells(i + 2) - 3 * x0)
- j = i
- End If
- Next i
- For i = 1 To 3
- x(i) = zakres_X.Cells(j + i - 1): y(i) = zakres_Y.Cells(j + i - 1)
- Next i
- x2w(1, 1) = 1: x2w(2, 1) = 1: x2w(3, 1) = 1 'tworzenie macierzy 3x3
- x2w(1, 2) = x(1): x2w(2, 2) = x(2): x2w(3, 2) = x(3)
- x2w(1, 3) = x(1) ^ 2: x2w(2, 3) = x(2) ^ 2: x2w(3, 3) = x(3) ^ 2
- A = WorksheetFunction.MMult(WorksheetFunction.MInverse(x2w), WorksheetFunction.Transpose(y))
- int_kw_popr = A(1, 1) + A(2, 1) * x0 + A(3, 1) * x0 * x0
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement