资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb.net矩阵相乘,矩阵与矩阵相乘

vb求两个矩阵的乘积

Public Sub MatrixMultiply(byref m() As Single, byref n() As Single,byref ReturnValue() As Single)

信阳网站建设公司创新互联建站,信阳网站设计制作,有大型网站制作公司丰富经验。已为信阳千余家提供企业网站建设服务。企业网站搭建\外贸网站建设要多少钱,请找那个售后服务好的信阳做网站的公司定做!

Dim i As Long, j As Long, k As Long, row As Long, column As Long, max As Long

row = UBound(m, 1)

column = UBound(n, 2)

max = UBound(m, 2)

ReDim ReturnValue(1 To row, 1 To column)

For i = 1 To row

For j = 1 To column

For k = 1 To max

ReturnValue(i, j) = ReturnValue(i, j) + m(i, k) * n(k, j)

Next

Next

Next

End Sub

VB.NET写了一个矩阵乘法的程序 代码如下

淳朴,古拙,淡泊,深远。闲居山林,逍遥河上,也许人只有摆脱了物欲的禁锢,才能让灵魂得到飞升。不识字烟波钓叟,傲杀人见万户侯;闲居山野的隐士,羞煞世上名利客。

斜风细雨,江南春色,落英缤纷。春水媚,绿波盈,青山横,白鹭飞。披蓑戴笠,心逐白云,意随鱼戏,行到水穷,坐看云起,卧听风韵松涛。不须归,不须归,只任心灵,放逐在深爱的自然里,忘世忘机。

《芥子园画谱》云:“与山水有顾盼,人似看山,山亦似俯而看人”。司空图《诗品冲淡》说:“遇之非深,即之逾稀。”空灵天真,非性情中人而不能为。梅妻鹤子友麋鹿,是怎样一种超逸?

求助!用Vb.net编写两个矩阵相乘!

Public Shared Sub Main()

Dim a As Integer, b As Integer, c As Integer, d As Integer

Console.WriteLine("该程序将求出两个矩阵的积:")

Console.WriteLine("请指定矩阵A的行数:")

a = Integer.Parse(Console.ReadLine())

Console.WriteLine("请指定矩阵A的列数:")

b = Integer.Parse(Console.ReadLine())

Dim MatrixA As Integer(,) = New Integer(a - 1, b - 1) {}

For i As Integer = 0 To a - 1

For j As Integer = 0 To b - 1

Console.WriteLine("请输入矩阵A第{0}行第{1}列的值:", i + 1, j + 1)

MatrixA(i, j) = Integer.Parse(Console.ReadLine())

Next

Next

Console.WriteLine("矩阵A输入完毕.")

Console.WriteLine("请指定矩阵B的行数:")

c = Integer.Parse(Console.ReadLine())

Console.WriteLine("请指定矩阵B的列数:")

d = Integer.Parse(Console.ReadLine())

Dim MatrixB As Integer(,) = New Integer(c - 1, d - 1) {}

For i As Integer = 0 To c - 1

For j As Integer = 0 To d - 1

Console.WriteLine("请输入矩阵A第{0}行第{1}列的值:", i + 1, j + 1)

MatrixB(i, j) = Integer.Parse(Console.ReadLine())

Next

Next

Console.WriteLine("矩阵B输入完毕.")

Console.WriteLine("矩阵A为:")

outputMatrix(MatrixA, a, b)

Console.WriteLine("矩阵B为:")

outputMatrix(MatrixB, c, d)

If b c Then

Console.WriteLine("矩阵A的列数与矩阵B的行数不相等,无法进行乘积运算!")

Return

Else

Console.WriteLine("矩阵A与矩阵B的乘积为:")

End If

Dim MatrixC As Integer(,) = New Integer(a - 1, d - 1) {}

For i As Integer = 0 To a - 1

For j As Integer = 0 To d - 1

MatrixC(i, j) = 0

For k As Integer = 0 To b - 1

MatrixC(i, j) += MatrixA(i, k) * MatrixB(k, j)

Next

Next

Next

outputMatrix(MatrixC, a, d)

End Sub

Private Shared Sub outputMatrix(MatrixX As Integer(,), rowCount As Integer, columnCount As Integer)

For i As Integer = 0 To rowCount - 1

For j As Integer = 0 To columnCount - 1

Console.Write(MatrixX(i, j) vbTab)

Next

Console.WriteLine()

Next

End Sub

End Class

矩阵相乘 VB代码

'建立4个label1(),index 0--3。6个label2(),index 0--5。6个text1(),index 0--5

'建立1个label3,两个command1和2

'Form1.MaxButton = False

Dim I As Byte, J As Byte, A As Byte, B As Byte

Dim M As Byte, N As Byte, MN As Byte

Dim JZ1() As Single, JZ2() As Single, JZ3() As Single

Dim SS As String

Private Sub Command1_Click()

If Command1.Caption = "确定" Then

Command1.Caption = "完成"

ReDim JZ1(1 To M, 1 To MN) As Single

ReDim JZ2(1 To MN, 1 To N) As Single

ReDim JZ3(1 To M, 1 To N) As Single

For I = 0 To 5

Text1(I).Locked = True

Text1(I).BackColor = HF0F0F0

Text1(I).BorderStyle = 0

Next I

Label3.Caption = "请输入相乘的两个矩阵,输入完成后按完成键"

For I = 1 To M

For J = 1 To MN

JZ1(I, J) = Val(InputBox("第一个矩阵____第" + Str(I) + "行 第" + Str(J) + "列元素:", "输入矩阵", 3))

CurrentX = 100 + (J - 1) * 350

CurrentY = 1000 + (I - 1) * 200

Print JZ1(I, J)

Next

Next

For I = 1 To MN

For J = 1 To N

JZ2(I, J) = Val(InputBox("第二个矩阵____第" + Str(I) + "行 第" + Str(J) + "列元素:", "输入矩阵", 3))

CurrentX = 3000 + (J - 1) * 350

CurrentY = 1000 + (I - 1) * 200

Print JZ2(I, J)

Next

Next

'Select Case M

ElseIf Command1.Caption = "完成" Then

Command1.Caption = "重新开始"

For I = 1 To M

For J = 1 To N

JZ3(I, J) = 0

For A = 1 To MN

JZ3(I, J) = JZ3(I, J) + JZ1(I, A) * JZ2(A, J)

Next

CurrentX = 6000 + (J - 1) * 350

CurrentY = 1000 + (I - 1) * 200

Print JZ3(I, J)

Next

Next

Else

Form_Load

End If

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Form_Load()

Cls

Form1.Width = 9000

Form1.Height = 7000

For I = 0 To 2

Label1(I).Width = 1000

Label1(I).Height = 200

Label1(I).Top = 0

Label1(I).Left = 700 + I * 3000

Label1(I).Caption = "第" + Str(I + 1) + "个矩阵"

Next

For I = 0 To 5

Text1(I).Width = 400

Text1(I).Height = 200

Text1(I).Top = 300

Label2(I).Width = 200

Label2(I).Height = Text1(I).Height

Label2(I).Top = Text1(I).Top + 50

Text1(I).Text = 2

Text1(I).Alignment = 1

If I Mod 2 Then

Text1(I).Left = I * 1500 - 300

Label2(I).Caption = "列"

Else

Text1(I).Left = 300 + I * 1500

Label2(I).Caption = "行"

End If

Label2(I).Left = Text1(I).Left + 450

Next

M = 2

N = 2

MN = 2

Text1(2).Locked = True

Text1(4).Locked = True

Text1(5).Locked = True

Text1(0).Locked = False

Text1(1).Locked = False

Text1(3).Locked = False

For I = 0 To 5

Text1(I).BackColor = HFFFFFF

Text1(I).BorderStyle = 1

Next I

Command1.Caption = "确定"

Command2.Caption = "退出"

Label3.Caption = "请输入矩阵的行和列,完成后按确定键"

End Sub

Private Sub Text1_Change(Index As Integer)

Text1(2).Text = Text1(1).Text

Text1(4).Text = Text1(0).Text

Text1(5).Text = Text1(3).Text

M = Val(Text1(0).Text)

MN = Val(Text1(1).Text)

N = Val(Text1(3).Text)

End Sub

已经运行过。

vb.net 向量和矩阵相乘,"return B(j)"报错“索引超出了数组界限”,程序如下,在线急等!!!

可以通过下断点方式,查看一下A() ,R(,) 元素的个数,是否为3和2


分享题目:vb.net矩阵相乘,矩阵与矩阵相乘
当前地址:http://www.cdkjz.cn/article/dsgihco.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220