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

來源:互聯網
上載者:User

標籤:

  1.數學定義

    n階行列式定義如下:

 

  2.演算法實現

  函數名: GetValue()

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

    Private Function GetValue()        Dim gValue As Double        Dim tempResultList As New List(Of Array)        Dim tempNumArray(RankLength - 1) As Integer ‘要進行全排列的序列        For i = 0 To RankLength - 1            tempNumArray(i) = i        Next        GetFullPerm(tempNumArray, 0, tempResultList)        Dim temp As Double        Dim tempData() As Integer        For i = 0 To tempResultList.Count - 1            temp = 1            tempData = tempResultList(i)            For j = 0 To RankLength - 1                temp = temp * TableData(j, tempData(j))            Next            temp = Math.Pow(-1, 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                Return TableData(iRow - 1, iCol - 1)            End Get            Set(ByVal value)                TableData(iRow - 1, iCol - 1) = value            End Set        End Property    Public ReadOnly Property value()        Get            Return GetValue()        End Get    End Property    Public Sub New(ByVal nRank As Integer)        Dim tempArray(nRank - 1, nRank - 1) As Double        TableData = tempArray        RankLength = nRank    End Sub    ‘求行列式的值    Private Function GetValue()        Dim gValue As Double        Dim tempResultList As New List(Of Array)        Dim tempNumArray(RankLength - 1) As Integer ‘要進行全排列的序列        For i = 0 To RankLength - 1            tempNumArray(i) = i        Next        GetFullPerm(tempNumArray, 0, tempResultList)        Dim temp As Double        Dim tempData() As Integer        For i = 0 To tempResultList.Count - 1            temp = 1            tempData = tempResultList(i)            For j = 0 To RankLength - 1                temp = temp * TableData(j, tempData(j))            Next            temp = Math.Pow(-1, 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        If LeftIndex = NumArray.Length - 1 Then            Dim tempArray(NumArray.Length - 1) As Integer            NumArray.CopyTo(tempArray, 0)            Result.Add(tempArray)        Else            temp = NumArray(LeftIndex)            For i = LeftIndex To NumArray.Length - 1                NumArray(LeftIndex) = NumArray(i)                NumArray(i) = temp ‘對換                GetFullPerm(NumArray, LeftIndex + 1, Result)                NumArray(i) = NumArray(LeftIndex)                NumArray(LeftIndex) = temp ‘還原對換            Next        End If    End Sub    ‘逆序數    Private Function GetInverseNum(ByVal NumArray() As Integer)        Dim Num As Integer = 0        For i = 0 To NumArray.Length - 1            For j = i To NumArray.Length - 1                If NumArray(i) > NumArray(j) Then Num += 1            Next        Next        Return Num    End FunctionEnd Class
View Code

 

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.