VB 用随机数(20~80)生成一个4行4列的矩阵A,求A的转置矩阵
End Sub 展开
已经完成:
Private Sub Picture1_Click()
Dim a(4, 4) As Integer, i As Integer, j As Integer, b(4, 4) As Integer
For i = 1 To 4
For j = 1 To 4
a(i, j) = Int(Rnd() * 61 + 20)
Picture1.Print a(i, j);
Next
Picture1.Print
Next
Picture1.Print
For i = 1 To 4
For j = 1 To 4
b(i, j) = a(j, i)
Picture1.Print b(i, j);
Next
Picture1.Print
Next
Picture1.Print
End Sub
如果。。我想把转置的放在picture2呢??单击“命令按钮转置”然后picture2出现picture1的矩阵的转置
Dim a(4, 4) As Integer
Private Sub Picture1_Click()
Dim i As Integer, j As Integer
For i = 1 To 4
For j = 1 To 4
a(i, j) = Int(Rnd() * 61 + 20)
Picture1.Print a(i, j);
Next
Picture1.Print
Next
Picture1.Print
End Sub
Private Sub Command1_Click()
Dim b(4, 4) As Integer
For i = 1 To 4
For j = 1 To 4
b(i, j) = a(j, i)
Picture2.Print b(i, j);
Next
Picture2.Print
Next
Picture2.Print
End Sub
我懒得给你重写,直接给你一个转置的函数,调用形式:bt = MatTrn(B),B为输入矩阵,bt为输出结果
Public Function MatTrn(x() As Double) As Double()
Dim n As Long
Dim m As Long
Dim i As Long
Dim j As Long, y() As Double
n = UBound(x, 1)
m = UBound(x, 2)
'If Not IsDimed(Y) Then
ReDim y(1 To m, 1 To n)
'End If
'ReDim Y(1 To m, 1 To n) As Double
For i = 1 To n
For j = 1 To m
y(j, i) = x(i, j)
Next j
Next i
MatTrn = y
End Function
For j= 1 To 4
For i= 1 To 4
Picture2.Print a(i, j);
Next
Picture2.Print
Next
Picture2.Print
要是想得到A的转置矩阵,代码如下:
dim b(4,4) as integer
For j= 1 To 4
For i= 1 To 4
b(j,i)=a(i, j) ;
Next
Next
Private Sub Picture1_Click()
这是矩阵A出现的代码
End Sub
然后
Private Sub command1_Click()
这是转置的代码,但是这样的话,上面的a(i,j)就会因程序结束而回到初始值。。不能用在这里。。是不是会这样啊?我不太懂啊?
End Sub