Смекни!
smekni.com

Метод Гаусса для расчета электрических цепей (стр. 2 из 2)

MSFlexGrid1. Row = 6

MSFlexGrid1. Col = 7

MSFlexGrid1. CellForeColor = vbGreen

MSFlexGrid1. Row = 5

MSFlexGrid1. Col = 7

MSFlexGrid1. CellForeColor = vbGreen

MSFlexGrid1. Row = 4

MSFlexGrid1. Col = 7

MSFlexGrid1. CellForeColor = vbGreen

'закрываем файл

Close #1

End If

End Sub

Sub Gauss ()

Dim i, j, k, r As Double

Calldann

n = 6

' метод

'поиск главного элемента в i-том столбце

For i = 1 To n

k = i

r = Abs (a (i, i))

For j = i + 1 To n

If Abs (a (j, i)) > r Then

k = j

r = a (j, i)

End If

Next j

If r = 0 Then Exit For

If k <> i Then

'перестоновка

r = X (k)

X (k) = X (i)

X (i) = r

For j = 1 To n

r = a (k, j)

a (k, j) = a (i, j)

a (i, j) = r

Next j

End If

'исключение i-ого неизвестного

r = a (i, i)

X (i) = X (i) / r

For j = 1 To n

a (i, j) = a (i, j) / r

Next j

For k = i + 1 To n

r = a (k, i)

X (k) = X (k) - r * X (i)

For j = 1 To n

a (k, j) = a (k, j) - r * a (i, j)

Next j

Next k

Next i

'обратный ход

For i = n - 1 To 1 Step - 1

For j = i + 1 To n

X (i) = X (i) - a (i, j) * X (j)

Next j

Next i

Text1. Text = Format (X (1), "0.000") & " A"

Text2. Text = Format (X (2), "0.000") & " A"

Text3. Text = Format (X (3), "0.000") & " A"

Text4. Text = Format (X (4), "0.000") & " A"

Text5. Text = Format (X (5), "0.000") & " A"

Text6. Text = Format (X (6), "0.000") & " A"

End Sub

Private Sub mnAbout_Click ()

frmAbout. Show

End Sub

Private Sub mnExit_Click ()

End

End Sub

Private Sub dann ()

n = 6

m = 7

a (1,1) = - 1

a (1,2) = 1

a (1,3) = 1

a (1,4) = 0

a (1,5) = 0

a (1,6) = 0

a (2,1) = 0

a (2,2) = 0

a (2,3) = - 1

a (2,4) = - 1

a (2,5) = 0

a (2,6) = 0

a (3,1) = 0

a (3,2) = 1

a (3,3) = 0

a (3,4) = 0

a (3,5) = 1

a (3,6) = 1

a (4,1) = rr (1)

a (4,2) = 0

a (4,3) = 0

a (4,4) = 0

a (4,5) = 0

a (4,6) = 0

a (5,1) = 0

a (5,2) = 0

a (5,3) = 0

a (5,4) = 0

a (5,5) = rr (2)

a (5,6) = 0

a (6,1) = 0

a (6,2) = 0

a (6,3) = 0

a (6,4) = 0

a (6,5) = rr (2)

a (6,6) = - rr (4) - rr (3)

X (1) = 0

X (2) = 0

X (3) = 0

X (4) = e (2) - e (3)

X (5) = e (1)

X (6) = e (1) + e (4) - e (5)

End Sub