我想知道VB6.0矩陣相成的寫法
是3*3的矩陣相乘
我寫了幾次不曉得哪裡有錯
一直跑步出來
如果回答好的我贈送20點
2005-04-25 13:57:27 · 3 個解答 · 發問者 Anonymous in 電腦與網際網路 ➔ 程式設計
Private Sub Command3_Click()
Label1.Caption = "*"
Text19.Text = Val(Text1.Text) * Val(Text10.Text) + Val(Text2.Text) * Val(Text13.Text) + Val(Text3.Text) * Val(Text16.Text)
End Sub
2005-04-25 18:09:45 · update #1
要如何在修改成最簡單的發法呢?
2005-04-25 18:10:24 · update #2
我是將
array x在表單內用text1(0)~text1(8)表示
array x在表單內用text2(0)~text2(8)表示
array x在表單內用text3(0)~text3(8)表示
X*Y=Z
表單上的index
X Y Z
0 1 2 0 1 2 0 1 2
3 4 5 3 4 5 3 4 5
6 7 8 6 7 8 6 7 8
這樣就可方便把他存成陣列
再用for迴圈來相乘存到z陣列
程式如下:
Private Sub Command1_Click()
Dim x(3, 3)
Dim y(3, 3)
Dim z(3, 3)
'將text1的值存入陣列x
For i = 0 To 8
x(i \ 3, i Mod 3) = Val(Text1(i).Text)
Next i
'將text2的值存入陣列y
For i = 0 To 8
y(i \ 3, i Mod 3) = Val(Text2(i).Text)
Next i
'做陣列相乘,存到z陣列
For i = 0 To 2
For j = 0 To 2
z(i, j) = 0
For k = 0 To 2
z(i, j) = z(i, j) + x(i, k) * y(k, j)
Next k
Next j
Next i
'將z陣列存到表單的text3
For i = 0 To 8
Text3(i).Text = Str(z(i \ 3, i Mod 3))
Next i
End Sub
2005-04-27 15:58:39 · answer #1 · answered by 翔文 4 · 0⤊ 0⤋
┌a b c┐ ┌j k l┐ ┌A D G┐
│d e f│x│m n o│=│B E H│
└g h i┘ └p q r┘ └C F I┘
A=aj+bm+cp
B=dj+em+fp
C=gj+hm+ip
D=ak+bn+cq
E=dk+en+fq
F=gk+hn+iq
G=al+bo+cr
H=dl+eo+fr
I=gl+ho+ir
就兩個二維陣列相乘,相加完後放到另一個二維陣列中, 作輸出
2005-04-26 02:06:32 補充:
寫一個這個,看會不會簡單一點
Function MetrixCell(a As TextBox, b As TextBox, c As TextBox, j As TextBox, m As TextBox, p As TextBox)
MetrixCell = Val(a.Text) * Val(j.Text) + Val(b.Text) * Val(m.Text) + Val(c.Text) * Val(p.Text)
End Function
2005-04-25 17:25:19 · answer #2 · answered by Anonymous · 0⤊ 0⤋
那把程式碼貼出來看看
不貼怎麼知道你錯在哪呢?
2005-04-25 14:22:29 · answer #3 · answered by Tony 6 · 0⤊ 0⤋