扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
Public Shared Sub Main()
创新互联是一家专业提供定边企业网站建设,专注与网站制作、成都网站制作、成都h5网站建设、小程序制作等业务。10年已为定边众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。
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
要实现什么样的功能呢?矩阵就是二维表吧,在.Net中有许多方法可以实现二维表,根据不同的需求选择适合的方法,你应该详细一点说明
在程序设计语言里,用二维数组来保存矩阵的值。
一维列矩阵,就是由:若干行、一列组成的二维数组。
一维行矩阵,就是由:一行、若干列组成的二维数组。
比如一维列矩阵,的输入:
dim a(10,1) as integer '10行,1列
dim i as integer
for i = 1 to 10
a(i,1) = inputbox("")
next i
'这是在vb6中的代码,在vb.net中基本差不多,你可以参考一下
Private Sub cmdCommand1_Click()
Me.AutoRedraw = True
Dim Grp
Grp = Array(1, 2, 3, 4, 5)
Dim i, j As Long
Dim StrPrt As String
For i = 0 To UBound(Grp)
'i为位移量
StrPrt = ""
For j = i To UBound(Grp)
StrPrt = StrPrt Grp(j)
Next j
For j = 0 To i - 1
StrPrt = StrPrt Grp(j)
Next j
Me.Print StrPrt
Next i
End Sub
没错!!
你的算法是:
1.定义三个变量,minValue(放最小值),X(放最小值的X坐标),Y(放最小值的Y坐标)。
2.遍历矩阵。在遍历过程中将最小值放在minValue中,最小值的X坐标放在X中,最小值的Y坐标放在X中。
给你一个函数 Public Sub Vect1XtoVect2(ByVal x1 As Double, ByVal y1 As Double, ByVal z1 As Double, _ ByVal x2 As Double, ByVal y2 As Double, ByVal z2 As Double, _ ByRef xNew As Double, ByRef yNew As Double, ByRef zNew As Double) '矢量叉积 xNew = y1 * z2 - z1 * y2 yNew = z1 * x2 - x1 * z2 zNew = x1 * y2 - y1 * x2 End Sub其中x1,y1,z1为第一个矢量,x2,y2,z2为第二个矢量xnew,ynew,znew为得到的新矢量
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流