'初等行变换之互换两行
Public Sub Matrix_Specify_Tow_Row_Exchange(Row_A_Index As Integer, Row_B_Index As Integer, temp_matrix() As Single)
Dim i As Integer
For i = 1 To UBound(temp_matrix, 2)
swap temp_matrix(Row_A_Index, i), temp_matrix(Row_B_Index, i)
Next i
End Sub
'初等行变换之一行自乘一个数后加至另一行上去
Public Sub Matrix_Single_Row_ShuChen_Addition_To_Other_Row(temp_matrix() As Single, Row_A_Index As Integer, Row_B_Index As Integer, k As Single)
Dim i As Integer
For i = 1 To UBound(temp_matrix, 2)
temp_matrix(Row_B_Index, i) = temp_matrix(Row_B_Index, i) + k * temp_matrix(Row_A_Index, i)
Next i
End Sub
'初等行变换之某一行的全体自乘一个数
Public Sub Matrix_Single_Row_ShuChen(k As Single, temp_a() As Single, Row_Index As Integer)
Dim i As Integer
For i = 1 To UBound(temp_a, 2)
temp_a(Row_Index, i) = k * temp_a(Row_Index, i)
Next i
End Sub
'最简行阶梯阵的计算。
Option Explicit
Public Function Matrix_Basic_Row_Transformation(temp_matrix() As Single)
Dim Row_Index As Integer, col_index As Integer, Row_Num As Integer, Col_Num As Integer
Dim i As Integer, j As Integer, Not_Zero_Row_Index As Integer
Dim temp_chen As Single
Dim flag As Boolean
Row_Num = UBound(temp_matrix, 1)
Col_Num = UBound(temp_matrix, 2)
Row_Index = 1: col_index = 1
Do While (Row_Index <= Row_Num And col_index <= Col_Num)
'Do While (col_index <= Col_Num)
flag = If_Specify_Col_Zero(temp_matrix, col_index, Row_Index, Not_Zero_Row_Index)
If (flag = False) Then
'FormTest.Print "did it!"
'If col_index = 2 And Row_Index = 2 Then output_matrix temp_matrix
If (Not_Zero_Row_Index <> Row_Index) Then
Matrix_Specify_Tow_Row_Exchange Row_Index, Not_Zero_Row_Index, temp_matrix
End If
'FormTest.List1.AddItem Row_Index
'FormTest.List2.AddItem col_index
For i = 1 To Row_Num
If (i <> Row_Index) Then
Matrix_Single_Row_ShuChen_Addition_To_Other_Row temp_matrix, Row_Index, i, -temp_matrix(i, col_index) / temp_matrix(Row_Index, col_index)
End If
'If Row_Index = 2 Then FormTest.List1.AddItem temp_matrix(i, Col_Num)
Next i
Matrix_Single_Row_ShuChen 1 / temp_matrix(Row_Index, col_index), temp_matrix, Row_Index
Row_Index = Row_Index + 1
col_index = col_index + 1
Else
'FormTest.Print col_index, Row_Index
col_index = col_index + 1
End If
Loop
End Function