Determinant (c): N-Step determinant

Source: Internet
Author: User

1. Mathematical Definitions

The N-step determinant is defined as follows:

2. Algorithm implementation

Function name: GetValue ()

Function: Returns the value of a determinant

    Private FunctionGetValue ()DimGvalue as Double        DimTempresultlist as NewList ( ofArray)DimTempnumarray (Ranklength-1) as Integer 'to make a sequence of all permutations         fori =0  toRanklength-1Tempnumarray (i) =INextgetfullperm (Tempnumarray,0, Tempresultlist)DimTemp as Double        DimTempData () as Integer         fori =0  toTempresultlist.count-1Temp=1TempData=tempresultlist (i) forj =0  toRanklength-1Temp= Temp *Tabledata (J, TempData (j))NextTemp= Math.pow (-1, Getinversenum (tempdata)) *Temp Gvalue+=TempNext        ReturnGvalueEnd Function

3. Complete determinant class (determinant)

Examples of Use:

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 ClassdeterminantPrivateTabledata (,) as Double    PrivateRanklength as Integer    'the order of the determinant     Public ReadOnly  PropertyRank ()Get            ReturnRanklengthEnd Get    End Property    'determinant irow element of row icol column         Public  PropertyItem (ByValIRow as Integer,ByValIcol as Integer)            Get                ReturnTabledata (IRow-1, Icol-1)            End Get            Set(ByValvalue) Tabledata (IRow-1, Icol-1) =valueEnd Set        End Property     Public ReadOnly  Propertyvalue ()Get            ReturnGetValue ()End Get    End Property     Public Sub New(ByValNrank as Integer)        DimTemparray (Nrank-1, Nrank-1) as DoubleTabledata=Temparray ranklength=NrankEnd Sub    'to find the value of a determinant    Private FunctionGetValue ()DimGvalue as Double        DimTempresultlist as NewList ( ofArray)DimTempnumarray (Ranklength-1) as Integer 'to make a sequence of all permutations         fori =0  toRanklength-1Tempnumarray (i)=INextgetfullperm (Tempnumarray,0, Tempresultlist)DimTemp as Double        DimTempData () as Integer         fori =0  toTempresultlist.count-1Temp=1TempData=tempresultlist (i) forj =0  toRanklength-1Temp= Temp *Tabledata (J, TempData (j))NextTemp= Math.pow (-1, Getinversenum (tempdata)) *Temp Gvalue+=TempNext        ReturnGvalueEnd Function    'Full arrangement    Private SubGetfullperm (ByValNumarray () as Integer,ByValLeftindex as Integer,ByRefResult asList ( ofArray)) DimTemp as Integer        IfLeftindex = Numarray.length-1  Then            DimTemparray (Numarray.length-1) as IntegerNumarray.copyto (Temparray,0) Result.add (temparray)ElseTemp=Numarray (Leftindex) fori = Leftindex toNumarray.length-1Numarray (Leftindex)=Numarray (i) Numarray (i)= Temp'SwapGetfullperm (Numarray, Leftindex +1, Result) Numarray (i)=Numarray (Leftindex) Numarray (leftindex)= Temp'Restore Swap            Next        End If    End Sub    'number of reverse order    Private FunctionGetinversenum (ByValNumarray () as Integer)        DimNum as Integer=0         fori =0  toNumarray.length-1             forj = I toNumarray.length-1                IfNumarray (i) > Numarray (j) ThenNum + =1            Next        Next        ReturnNumEnd FunctionEnd Class
View Code

Determinant (c): N-Step determinant

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.