Matrix 计算之旅1---初等行变换

'初等行变换之互换两行
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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值