Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Центр помощи > [C++]Вычисление определителя матрицы


Автор: kostyaizznu 23.12.2008, 18:50
Программа вычисляет определитель вводимой матрицы

Добавте, пожалуйста, кнопку "Произвольное заполнение"...При нажатии которой матрица заполняется рандомно целыми числами и вычисляется определитель.

Код

Option Explicit
Dim i, j, k, l, m As Byte
Dim n As Integer
Dim C, d, s As Double
Dim B(9, 9) As Double
Static Function d2(i1 As Byte, i2 As Byte, j1 As Byte, j2 As Byte) As Double
d2 = B(i1, j1) - B(i2, j2)
End Function
Static Function d3(i1 As Byte, i2 As Byte, i3 As Byte, j1 As Byte, j2 As Byte, j3 As Byte) As Double
d3 = B(i1, j1) * B(i2, j2) * B(i3, j3) + B(i1, j2) * B(i2, j3) * B(i3, j1) + B(i2, j1) * B(i3, j2) * B(i1, j3) - B(i1, j3) * B(i2, j2) * B(i3, j1) - B(i1, j1) * B(i2, j3) * B(i3, j2) - B(i1, j2) * B(i2, j1) * B(i3, j3)
End Function
Static Function d4(i1 As Byte, i2 As Byte, i3 As Byte, i4 As Byte, j1 As Byte, j2 As Byte, j3 As Byte, j4 As Byte) As Double
d4 = B(i1, j1) * d3(i2, i3, i4, j2, j3, j4) - B(i1, j2) * d3(i2, i3, i4, j1, j3, j4) + B(i1, j3) * d3(i2, i3, i4, j1, j2, j4) - B(i1, j4) * d3(i2, i3, i4, j1, j2, j3)
End Function
Static Function d5(i1 As Byte, i2 As Byte, i3 As Byte, i4 As Byte, i5 As Byte, j1 As Byte, j2 As Byte, j3 As Byte, j4 As Byte, j5 As Byte) As Double
d5 = B(i1, j1) * d4(i2, i3, i4, i5, j2, j3, j4, j5) - B(i1, j2) * d4(i2, i3, i4, i5, j1, j3, j4, j5) + B(i1, j3) * d4(i2, i3, i4, i5, j1, j2, j4, j5) - B(i1, j4) * d4(i2, i3, i4, i5, j1, j2, j3, j5) + B(i1, j5) * d4(i2, i3, i4, i5, j1, j2, j3, j4)
End Function
Static Function d6(i1 As Byte, i2 As Byte, i3 As Byte, i4 As Byte, i5 As Byte, i6 As Byte, j1 As Byte, j2 As Byte, j3 As Byte, j4 As Byte, j5 As Byte, j6 As Byte) As Double
d6 = B(i1, j1) * d5(i2, i3, i4, i5, i6, j2, j3, j4, j5, j6) - B(i1, j2) * d5(i2, i3, i4, i5, i6, j1, j3, j4, j5, j6) + B(i1, j3) * d5(i2, i3, i4, i5, i6, j1, j2, j4, j5, j6) - B(i1, j4) * d5(i2, i3, i4, i5, i6, j1, j2, j3, j5, j6) + B(i1, j5) * d5(i2, i3, i4, i5, i6, j1, j2, j3, j4, j6) - B(i1, j6) * d5(i2, i3, i4, i5, i6, j1, j2, j3, j4, j5)
End Function
Static Function d7(i1 As Byte, i2 As Byte, i3 As Byte, i4 As Byte, i5 As Byte, i6 As Byte, i7 As Byte, j1 As Byte, j2 As Byte, j3 As Byte, j4 As Byte, j5 As Byte, j6 As Byte, j7 As Byte) As Double
d7 = B(i1, j1) * d6(i2, i3, i4, i5, i6, i7, j2, j3, j4, j5, j6, j7) - B(i1, j2) * d6(i2, i3, i4, i5, i6, i7, j1, j3, j4, j5, j6, j7) + B(i1, j3) * d6(i2, i3, i4, i5, i6, i7, j1, j2, j4, j5, j6, j7) - B(i1, j4) * d6(i2, i3, i4, i5, i6, i7, j1, j2, j3, j5, j6, j7) + B(i1, j5) * d6(i2, i3, i4, i5, i6, i7, j1, j2, j3, j4, j6, j7) - B(i1, j6) * d6(i2, i3, i4, i5, i6, i7, j1, j2, j3, j4, j5, j7) + B(i1, j6) * d6(i2, i3, i4, i5, i6, i7, j1, j2, j3, j4, j5, j7) - B(i1, j7) * d6(i2, i3, i4, i5, i6, i7, j1, j2, j3, j4, j5, j6)
End Function
Static Function d8(i1 As Byte, i2 As Byte, i3 As Byte, i4 As Byte, i5 As Byte, i6 As Byte, i7 As Byte, i8 As Byte, j1 As Byte, j2 As Byte, j3 As Byte, j4 As Byte, j5 As Byte, j6 As Byte, j7 As Byte, j8 As Byte) As Double
d8 = B(i1, j1) * d7(i2, i3, i4, i5, i6, i7, i8, j2, j3, j4, j5, j6, j7, j8) - B(i1, j2) * d7(i2, i3, i4, i5, i6, i7, i8, j1, j3, j4, j5, j6, j7, j8) + B(i1, j3) * d7(i2, i3, i4, i5, i6, i7, i8, j1, j2, j4, j5, j6, j7, j8) - B(i1, j4) * d7(i2, i3, i4, i5, i6, i7, i8, j1, j2, j3, j5, j6, j7, j8) + B(i1, j5) * d7(i2, i3, i4, i5, i6, i7, i8, j1, j2, j3, j4, j6, j7, j8) - B(i1, j6) * d7(i2, i3, i4, i5, i6, i7, i8, j1, j2, j3, j4, j5, j7, j8) + B(i1, j7) * d7(i2, i3, i4, i5, i6, i7, i8, j1, j2, j3, j4, j5, j6, j8) - B(i1, j8) * d7(i2, i3, i4, i5, i6, i7, i8, j1, j2, j3, j4, j5, j6, j7)
End Function
Static Function d9(i1 As Byte, i2 As Byte, i3 As Byte, i4 As Byte, i5 As Byte, i6 As Byte, i7 As Byte, i8 As Byte, i9 As Byte, j1 As Byte, j2 As Byte, j3 As Byte, j4 As Byte, j5 As Byte, j6 As Byte, j7 As Byte, j8 As Byte, j9 As Byte) As Double
d9 = B(i1, j1) * d8(i2, i3, i4, i5, i6, i7, i8, i9, j2, j3, j4, j5, j6, j7, j8, j9) - B(i1, j2) * d8(i2, i3, i4, i5, i6, i7, i8, i9, j1, j3, j4, j5, j6, j7, j8, j9) + B(i1, j3) * d8(i2, i3, i4, i5, i6, i7, i8, i9, j1, j2, j4, j5, j6, j7, j8, j9) - B(i1, j4) * d8(i2, i3, i4, i5, i6, i7, i8, i9, j1, j2, j3, j5, j6, j7, j8, j9) + B(i1, j5) * d8(i2, i3, i4, i5, i6, i7, i8, i9, j1, j2, j3, j4, j6, j7, j8, j9) - B(i1, j6) * d8(i2, i3, i4, i5, i6, i7, i8, i9, j1, j2, j3, j4, j5, j7, j8, j9) + B(i1, j7) * d8(i2, i3, i4, i5, i6, i7, i8, i9, j1, j2, j3, j4, j5, j6, j8, j9) - B(i1, j8) * d8(i2, i3, i4, i5, i6, i7, i8, i9, j1, j2, j3, j4, j5, j6, j7, j9) + B(i1, j9) * d8(i2, i3, i4, i5, i6, i7, i8, i9, j1, j2, j3, j4, j5, j6, j7, j8)
End Function
Static Function d10(i1 As Byte, i2 As Byte, i3 As Byte, i4 As Byte, i5 As Byte, i6 As Byte, i7 As Byte, i8 As Byte, i9 As Byte, i10 As Byte, j1 As Byte, j2 As Byte, j3 As Byte, j4 As Byte, j5 As Byte, j6 As Byte, j7 As Byte, j8 As Byte, j9 As Byte, j10 As Byte) As Double
d10 = B(i1, j1) * d9(i2, i3, i4, i5, i6, i7, i8, i9, i10, j2, j3, j4, j5, j6, j7, j8, j9, j10) - B(i1, j2) * d9(i2, i3, i4, i5, i6, i7, i8, i9, i10, j1, j3, j4, j5, j6, j7, j8, j9, j10) + B(i1, j3) * d9(i2, i3, i4, i5, i6, i7, i8, i9, i10, j1, j2, j4, j5, j6, j7, j8, j9, j10) - B(i1, j4) * d9(i2, i3, i4, i5, i6, i7, i8, i9, i10, j1, j2, j3, j5, j6, j7, j8, j9, j10) + B(i1, j5) * d9(i2, i3, i4, i5, i6, i7, i8, i9, i10, j1, j2, j3, j4, j6, j7, j8, j9, j10) - B(i1, j6) * d9(i2, i3, i4, i5, i6, i7, i8, i9, i10, j1, j2, j3, j4, j5, j7, j8, j9, j10) + B(i1, j7) * d9(i2, i3, i4, i5, i6, i7, i8, i9, i10, j1, j2, j3, j4, j5, j6, j8, j9, j10) - B(i1, j8) * d9(i2, i3, i4, i5, i6, i7, i8, i9, i10, j1, j2, j3, j4, j5, j6, j7, j9, j10) + B(i1, j9) * d9(i2, i3, i4, i5, i6, i7, i8, i9, i10, j1, j2, j3, j4, j5, j6, j7, j8, j10) - B(i1, j10) * d9(i2, i3, i4, i5, i6, i7, i8, i9, i10, j1, j2, j3, j4, j5, j6, j7, j8, j9)
End Function
Private Sub det_Click()
s = 1
For i = 0 To n
    For j = 0 To n
        B(i, j) = Val(a(10 * i + j).Text)
    Next j
Next i
Select Case n
Case 0: s = B(0, 0)
Case 1: s = B(0, 0) * B(1, 1) - B(0, 1) * B(1, 0)
Case 2: s = d3(0, 1, 2, 0, 1, 2)
Case 3: s = d4(0, 1, 2, 3, 0, 1, 2, 3)
Case 4: s = d5(0, 1, 2, 3, 4, 0, 1, 2, 3, 4)
Case 5: s = d6(0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5)
Case 6: s = d7(0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6)
Case 7: s = d8(0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7)
Case 8: s = d9(0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8)
Case 9: s = d10(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
End Select
vyvod.Caption = "det = " & s
det.Visible = False
vvod.Visible = True
Label1.Visible = True
n1.Visible = True
End Sub
Private Sub Form_Load()
n = 9
End Sub
Private Sub vvod_Click()
vyvod.Caption = ""
For i = 0 To n
   For j = 0 To n
     a(10 * i + j).Visible = False
     a(10 * i + j).Text = ""
   Next j
Next i
n = Val(n1.Text)
Select Case n
Case Is < 0: MsgBox " Размерность матрицы должна бить положительной!!!", 16, "ERROR"
Case Is = 0: MsgBox "Матрица без элементов... Что это?!", , "ERROR"
Case Is > 10: MsgBox "Размерность матрицы в данной программе не может быть больше 10!", , "ERROR"
Case Else: n = n - 1
For i = 0 To n
   For j = 0 To n
     a(10 * i + j).Visible = True
   Next j
Next i
vvod.Visible = False
Label1.Visible = False
n1.Visible = False
det.Visible = True
End Select
End Sub

Автор: 2p0i 23.12.2008, 18:54
Это C++?  smile 

Автор: Dmi3ev 23.12.2008, 23:28
kostyaizznu, это VB  smile хотя бы узнал, на каком языке пишешь  smile 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)