行列式(三):n阶行列式

1.数学定义

    n阶行列式定义如下:

行列式(三):n阶行列式

2.算法实现

  函数名: GetValue()

  功能:返回一个行列式的值

    Private Function GetValue()
        Dim gValue As Double
        Dim tempResultList As New List(Of Array)
        ) As Integer '要进行全排列的序列

            tempNumArray(i) = i
        Next
        GetFullPerm(tempNumArray, , tempResultList)
        Dim temp As Double
        Dim tempData() As Integer

            temp =
            tempData = tempResultList(i)

                temp = temp * TableData(j, tempData(j))
            Next
            temp = Math.Pow(-, GetInverseNum(tempData)) * temp
            gValue += temp
        Next
        Return gValue
    End Function

3.完整的行列式类(determinant)

  使用示例:

Dim d As New Determinant(3)
d.Item(1, 1) = 1
d.Item(2, 2) = 2
d.Item(3, 3) = 4
Console.write(d.value)

Public Class Determinant
    Private TableData(,) As Double
    Private RankLength As Integer
    '行列式的阶
    Public ReadOnly Property Rank()
        Get
            Return RankLength
        End Get
    End Property
    '行列式第iRow行第iCol列的元素
        Public Property Item(ByVal iRow As Integer, ByVal iCol As Integer)
            Get
                , iCol - )
            End Get
            Set(ByVal value)
                TableData(iRow - , iCol - ) = value
            End Set
        End Property
    Public ReadOnly Property value()
        Get
            Return GetValue()
        End Get
    End Property
    Public Sub New(ByVal nRank As Integer)
        , nRank - ) As Double
        TableData = tempArray
        RankLength = nRank
    End Sub
    '求行列式的值
    Private Function GetValue()
        Dim gValue As Double
        Dim tempResultList As New List(Of Array)
        ) As Integer '要进行全排列的序列

            tempNumArray(i) = i
        Next
        GetFullPerm(tempNumArray, , tempResultList)
        Dim temp As Double
        Dim tempData() As Integer

            temp =
            tempData = tempResultList(i)

                temp = temp * TableData(j, tempData(j))
            Next
            temp = Math.Pow(-, GetInverseNum(tempData)) * temp
            gValue += temp
        Next
        Return gValue
    End Function
    '全排列
    Private Sub GetFullPerm(ByVal NumArray() As Integer, ByVal LeftIndex As Integer, ByRef Result As List(Of Array))
        Dim temp As Integer
         Then
            ) As Integer
            NumArray.CopyTo(tempArray, )
            Result.Add(tempArray)
        Else
            temp = NumArray(LeftIndex)

                NumArray(LeftIndex) = NumArray(i)
                NumArray(i) = temp '对换
                GetFullPerm(NumArray, LeftIndex + , Result)
                NumArray(i) = NumArray(LeftIndex)
                NumArray(LeftIndex) = temp '还原对换
            Next
        End If
    End Sub
    '逆序数
    Private Function GetInverseNum(ByVal NumArray() As Integer)

            Next
        Next
        Return Num
    End Function
End Class
上一篇:Django组件 之中间件


下一篇:thinkphp5的生命周期