包含vb.net求行列式的值的词条
求行列式的值代码
Option Explicit Option Base 1 Private Sub Form_Load() Dim i As Long n = Val(InputBox("请输入行列式的阶数!", "输入框")) If n 2 Then MsgBox "输入错误阶数必须大于1!" vbCrLf "请单击重试重新输入!", vbCritical, "系统提示" Exit Sub Command2.TabIndex = 1 End If If n 9 Then MsgBox "输入错误本程序只能计算10阶以下的行列式!" "请单击重试重新输入!", vbCritical, "系统提示" 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 "请在文本框里按行排列输入行列式" vbCrLf "注意用一个空格隔开!", 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() 为输入行列式的字符串数组 '//sz3()为二维行列式数组 '//str2为1到n组成的字符串123456.....n 为全局变量 '//str3为str2的全排列所组成的字符串每种排列以“,”隔开 str1 = Text1.Text If Len(str1) 2 * n ^ 2 - 1 Then MsgBox "输入错误!" vbCrLf n "阶行列式中元素个数应为" n ^ 2 "!" vbCrLf "请查看是否个元素之间都用空格隔开及个数是否正确!" vbCrLf "请点击重试重新输入!", vbCritical, "系统提示" Text1.Text = "" Exit Sub End If st() = Split(str1) '取得行列式的数据 ReDim sz3(n, s) As Long For i = 1 To n For j = 1 To s k = (i - 1) * s + j '按行排列行列式中第k个数,k与i,j的关系 sz3(i, j) = Val(st(k - 1)) '把原数组按行排列存入一个二维数组 Next j Next i Permutation "", str2, str3 sz1() = Split(str3, ",") '取n!个全排列存入 数组 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)) '顺序取每个全排列中的数字存入数组sz2() Next i For i = 1 To n m = m * sz3(sz2(i), i) '求元素之积 Next i sum = sum + arr(sz2(), n) * m 'n!个积相加并相应冠上正负号 Next j Text2.Text = sum End Sub Private Sub Command2_Click() Dim i As Long n = Val(InputBox("请输入行列式的阶数!", "输入框")) If n 2 Then MsgB 行列式ox "输入错误阶数必须大于1!" vbCrLf "请单击重试重新输入!", vbCritical, "系统提示" Exit Sub Command2.TabIndex = 1 End If If n 9 Then MsgBox "输入错误本程序只能计算10阶一下的行列式!" "请单击重试重新输入!", vbCritical, "系统提示" 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 "请在文本框里按行排列输入行列式" vbCrLf "注意用一个空格隔开!", vbOKOnly, "信息提示" Text1.Text = "" End Sub 模块1递 行列式归法求全排列 Option Explicit Option Base 1 '递归求全排列并返回全排列所组成的字符串 '算法描述: '以8位为例,求8位数的全排列,其实是8位中任取一位 '在后加上其余7位的全排列 '7 位:任取一位,其后跟剩下6位的全排列 '…… '这样就有两部分,一部分为前面的已经取出来的串,另一部分为后面即将进行的全排列的串 '参数pre即为前面已经取出来的串 '参数s 行列式即为将要进行排列的串 '参数str即为返回全排列所组成的字符串,每种排列以“,”隔开 Public Sub Permutation(pre As String, s As String, str As String) Dim i As Long '// 如果要排列的串长度为1,则返回 If Len(s) = 1 Then '//将排列数以“,”隔开存入一个字符串 str = str "," pre s Exit 行列式Sub End If '// for循环即是取出待排列的串的任一位 For i = 1 To Len(s) '// 递归,将取出的字符并入已经取出的串 '// 那么剩下的串即为待排列的串 Permutation pre Mid$(s, i, 1), Left$(s, i - 1) Mid$(s, i + 1), str Next i End Sub 模块2求逆序数 Option Explicit Opt 行列式ion Base 1 Public n As Long, s As Long, str2 As String '//求存入a()数组排列为奇排列还偶排列如果为奇排列返回-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
站在用户的角度思考问题,与客户深入沟通,找到华坪网站设计与华坪网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站建设、成都网站设计、企业官网、英文网站、手机端网站、网站推广、申请域名、网页空间、企业邮箱。业务覆盖华坪地区。
用vb.net编程,建立一个m行n列的矩阵,找出其中最小的元素所在的行和列,并输出该值及其行、列位置
没错!!
你的算法是:
1.定义三个变量,minValue(放最小值),X(放最小值的X坐标),Y(放最小值的Y坐标)。
2.遍历矩阵。在遍历过程中将最小值放在minValue中,最小值的X坐标放在X中,最小值的Y坐标放在X中。
哪位大神知道怎么用vb求一个矩阵的行列式,讲讲大致思路就行
以下是直接利用行列式定义以及逆序数法计算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://myzitong.com/article/heceop.html