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