Option Explicit Option Base 1 Private Sub Form_Load() Dim i As Long n = Val(InputBox("請輸入行列式的階數(shù)!", "輸入框")) If n 2 Then MsgBox "輸入錯(cuò)誤階數(shù)必須大于1!" vbCrLf "請單擊重試重新輸入!", vbCritical, "系統(tǒng)提示" Exit Sub Command2.TabIndex = 1 End If If n 9 Then MsgBox "輸入錯(cuò)誤本程序只能計(jì)算10階以下的行列式!" "請單擊重試重新輸入!", vbCritical, "系統(tǒng)提示" Exit Sub Command2.TabIndex = 1 End If str2 = "1" For i = 2 To n str2 = str2 i '組成1到n組成的字符串123456.....n Next i s = n MsgBox "請?jiān)谖谋究蚶锇葱信帕休斎胄辛惺? vbCrLf "注意用一個(gè)空格隔開!", vbOKOnly, "信息提示" Text1.TabIndex = 1 Text1.Text = "" End Sub Private Sub Command1_Click() Dim i As Long, j As Long, k As Long, m As Long, sum As Long, w As Long Dim strb As String, sz1() As String, sz2() As Long, sz3() As Long Dim str1 As String, str3 As String, st() As String ReDim sa(n) As Long, sz2(n) As Long '//st() 為輸入行列式的字符串?dāng)?shù)組 '//sz3()為二維行列式數(shù)組 '//str2為1到n組成的字符串123456.....n 為全局變量 '//str3為str2的全排列所組成的字符串每種排列以“,”隔開 str1 = Text1.Text If Len(str1) 2 * n ^ 2 - 1 Then MsgBox "輸入錯(cuò)誤!" vbCrLf n "階行列式中元素個(gè)數(shù)應(yīng)為" n ^ 2 "!" vbCrLf "請查看是否個(gè)元素之間都用空格隔開及個(gè)數(shù)是否正確!" vbCrLf "請點(diǎn)擊重試重新輸入!", vbCritical, "系統(tǒng)提示" Text1.Text = "" Exit Sub End If st() = Split(str1) '取得行列式的數(shù)據(jù) ReDim sz3(n, s) As Long For i = 1 To n For j = 1 To s k = (i - 1) * s + j '按行排列行列式中第k個(gè)數(shù),k與i,j的關(guān)系 sz3(i, j) = Val(st(k - 1)) '把原數(shù)組按行排列存入一個(gè)二維數(shù)組 Next j Next i Permutation "", str2, str3 sz1() = Split(str3, ",") '取n!個(gè)全排列存入 數(shù)組 sz1() For j = 1 To JC(n) m = 1 '每次都降m初始為1 strb = sz1(j) '每次取出一種排列存入strb For i = 1 To n sz2(i) = Val(Mid(strb, i, 1)) '順序取每個(gè)全排列中的數(shù)字存入數(shù)組sz2() Next i For i = 1 To n m = m * sz3(sz2(i), i) '求元素之積 Next i sum = sum + arr(sz2(), n) * m 'n!個(gè)積相加并相應(yīng)冠上正負(fù)號 Next j Text2.Text = sum End Sub Private Sub Command2_Click() Dim i As Long n = Val(InputBox("請輸入行列式的階數(shù)!", "輸入框")) If n 2 Then MsgB 行列式ox "輸入錯(cuò)誤階數(shù)必須大于1!" vbCrLf "請單擊重試重新輸入!", vbCritical, "系統(tǒng)提示" Exit Sub Command2.TabIndex = 1 End If If n 9 Then MsgBox "輸入錯(cuò)誤本程序只能計(jì)算10階一下的行列式!" "請單擊重試重新輸入!", vbCritical, "系統(tǒng)提示" Exit 行列式Sub Command2.TabIndex = 1 End If str2 = "1" For i = 2 To n str2 = str2 i '組成1到n組成的字符串123456.....n Next i s = n MsgBox "請?jiān)谖谋究蚶锇葱信帕休斎胄辛惺? vbCrLf "注意用一個(gè)空格隔開!", vbOKOnly, "信息提示" Text1.Text = "" End Sub 模塊1遞 行列式歸法求全排列 Option Explicit Option Base 1 '遞歸求全排列并返回全排列所組成的字符串 '算法描述: '以8位為例,求8位數(shù)的全排列,其實(shí)是8位中任取一位 '在后加上其余7位的全排列 '7 位:任取一位,其后跟剩下6位的全排列 '…… '這樣就有兩部分,一部分為前面的已經(jīng)取出來的串,另一部分為后面即將進(jìn)行的全排列的串 '參數(shù)pre即為前面已經(jīng)取出來的串 '參數(shù)s 行列式即為將要進(jìn)行排列的串 '參數(shù)str即為返回全排列所組成的字符串,每種排列以“,”隔開 Public Sub Permutation(pre As String, s As String, str As String) Dim i As Long '// 如果要排列的串長度為1,則返回 If Len(s) = 1 Then '//將排列數(shù)以“,”隔開存入一個(gè)字符串 str = str "," pre s Exit 行列式Sub End If '// for循環(huán)即是取出待排列的串的任一位 For i = 1 To Len(s) '// 遞歸,將取出的字符并入已經(jīng)取出的串 '// 那么剩下的串即為待排列的串 Permutation pre Mid$(s, i, 1), Left$(s, i - 1) Mid$(s, i + 1), str Next i End Sub 模塊2求逆序數(shù) Option Explicit Opt 行列式ion Base 1 Public n As Long, s As Long, str2 As String '//求存入a()數(shù)組排列為奇排列還偶排列如果為奇排列返回-1,偶排列返回1 Public Function arr(a() As Long, ByVal n As Long) As Integer Dim i As Long, j As Long, k As Long, m As Long For i = 1 To n - 1 m = i For j = m + 1 To n If a(i) a(j) Then k = k + 1 Next Next arr = (-1) ^ k End Function 模塊3遞歸法求階乘 Option Explicit '//遞歸法求階乘 Public Function JC(n As Long) As Double If n 2 Then JC = 1: Exit Function JC = n * JC(n - 1) End Function
站在用戶的角度思考問題,與客戶深入溝通,找到華坪網(wǎng)站設(shè)計(jì)與華坪網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、申請域名、網(wǎng)頁空間、企業(yè)郵箱。業(yè)務(wù)覆蓋華坪地區(qū)。
沒錯(cuò)!!
你的算法是:
1.定義三個(gè)變量,minValue(放最小值),X(放最小值的X坐標(biāo)),Y(放最小值的Y坐標(biāo))。
2.遍歷矩陣。在遍歷過程中將最小值放在minValue中,最小值的X坐標(biāo)放在X中,最小值的Y坐標(biāo)放在X中。
以下是直接利用行列式定義以及逆序數(shù)法計(jì)算6階行列式的fortran77程序,供參考。
c 求6階行列式的值
real?a(6,6),ip(6)
data?a/2,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,
1 2,3,4,5,1,6,1,1,1,1,1,2/
f=0
do?10?i=1,6
do?20?j=1,6
if?(j.eq.i)?goto?20
do?30?k=1,6
if?(k.eq.i.or.k.eq.j)?goto?30
do?40?l=1,6
if?(l.eq.i.or.l.eq.j.or.l.eq.k)?goto?40
do?50?m=1,6
if?(m.eq.i.or.m.eq.j.or.m.eq.k.or.m.eq.l)?goto?50
n=21-i-j-k-l-m
ip(1)=i
ip(2)=j
ip(3)=k
ip(4)=l
ip(5)=m
ip(6)=n
mm=0
do?1000?ii=1,5
do?1000?jj=ii+1,6
1000 if?(ip(ii).gt.ip(jj))?mm=mm+1
if?(mod(mm,2).eq.0)?then?
sign=1
else
sign=-1
endif
c t=a(1,i)*a(2,j)*a(3,k)*a(4,l)*a(5,m)*a(6,n)*(-1)**mm*1.0
c write(*,*)t
t=sign*a(1,i)*a(2,j)*a(3,k)*a(4,l)*a(5,m)*a(6,n)
f=f+t
50 continue
40 continue
30 continue
20 continue
10 continue
write(*,*)f
end
新聞名稱:包含vb.net求行列式的值的詞條
本文地址:http://vcdvsql.cn/article8/heceop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、網(wǎng)頁設(shè)計(jì)公司、企業(yè)建站、營銷型網(wǎng)站建設(shè)、外貿(mào)建站、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)