⑴ VB矩陣乘法的問題
1、ReDim g(7, 8), a(7, 8), c(7, 8)
將把這3個數組的值悄數銀全部賦值為零。畢枯
2、g(i, j) = -a(i, k3) * c(k3, j)
這個不是矩陣運啟宴算相乘的運算。
矩陣相乘的運算是:g(i, j) =g(i, j)+a(i, k3) * c(k3, j)
⑵ VB中怎樣實現計算自定義的1*5與5*5矩陣相乘
Dim CS() As Variant
Dim A(5) As Single
Dim B(5, 5) As Single
Dim C(5) As Single
Dim I As Integer, J As Integer
Private Sub Form_Click()
Form1.AutoRedraw = True
Form1.Cls
Print "A矩陣:"
For I = 1 To 5
A(I) = CS(I - 1)
If A(I) > 0 And A(I) < 1 Then
Print Format(A(I), "0.##");
Else
Print A(I);
End If
Print " ";
Next
Print
Print "B矩陣:"
For I = 1 To 5
For J = 1 To 5
B(I, J) = I - J
B(I, J) = Val(InputBox("第" & I & "行神蠢宴第" & J & "個元素"檔乎, "輸入B矩陣", B(I, J)))
Print B(I, J);
Next
Print
Next
Print "C(=A*B)矩陣:"
For I = 1 To 5
For J = 1 To 5
C(I) = C(I) + A(J) * B(J, I)
Next
If Abs(C(I)) > 0 And Abs(C(I)) < 1 Then
Print " "; Format(C(I), "0.##"游銀); " ";
Else
Print C(I);
End If
Next
Print
End Sub
Private Sub Form_Load()
CS = Array(0.3, 0.32, 0.25, 0.07, 0.05)
End Sub
如有其他要求,請留言!
⑶ vb 矩陣乘法運算
Option Explicit
Dim a() As Integer
Dim b() As Integer
Dim d As Integer
Dim m As Integer
Dim n As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer
d = InputBox("請輸判碧入A矩陣行數", "提示")
n = InputBox("請輸入A矩陣列數", "提示")
ReDim a(d, n) As Integer
For i = 1 To d
For j = 1 To n
a(i, j) = InputBox("請輸入矩陣A", "提示")
Picture1.Print a(i, j);
Next j
Picture1.Print
Next i
Picture1.Print
End Sub
'矩陣B輸入程序
Private Sub Command2_Click()
Dim c As Integer
Dim i As Integer, j As Integer
c = InputBox("請輸入B矩陣行肆行數", "裂沖嘩提示")
⑷ 矩陣相乘 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 矩陣乘法提示下標越界
你貼的代碼不完整啊
⑹ VBA矩陣乘法
這個不用自己禪空陸虧扮寫那麼麻煩把 有個內置函數賀頃MMULT 就是算 矩陣乘法的!
如果要在VBA 裡面調用,闊以用
application.worksheetfunction.mmult() 調用