⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 05.frm

📁 实现矩阵一般功能运算,矩阵相加,减,相乘等功能
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   BackColor       =   &H00FFC0C0&
   Caption         =   "矩阵相乘"
   ClientHeight    =   8085
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   11880
   FillColor       =   &H00FFFFFF&
   ForeColor       =   &H8000000A&
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   ScaleHeight     =   8085
   ScaleWidth      =   11880
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command6 
      Caption         =   "输入矩阵Y"
      Enabled         =   0   'False
      Height          =   600
      Left            =   5040
      TabIndex        =   11
      Top             =   5760
      Width           =   1600
   End
   Begin VB.CommandButton Command5 
      Caption         =   "积"
      Enabled         =   0   'False
      Height          =   600
      Left            =   9000
      TabIndex        =   10
      Top             =   5760
      Width           =   1600
   End
   Begin VB.PictureBox Picture3 
      BackColor       =   &H00FFC0C0&
      Height          =   3495
      Left            =   4080
      ScaleHeight     =   3435
      ScaleWidth      =   3435
      TabIndex        =   6
      Top             =   1320
      Width           =   3495
   End
   Begin VB.PictureBox Picture2 
      BackColor       =   &H00FFC0C0&
      Height          =   3495
      Left            =   480
      ScaleHeight     =   3435
      ScaleWidth      =   3195
      TabIndex        =   5
      Top             =   1320
      Width           =   3255
   End
   Begin VB.CommandButton Command4 
      Caption         =   "清除再来"
      Height          =   600
      Left            =   1200
      TabIndex        =   4
      Top             =   6960
      Width           =   1600
   End
   Begin VB.PictureBox Picture1 
      BackColor       =   &H00FFC0C0&
      Height          =   3495
      Left            =   7920
      ScaleHeight     =   3435
      ScaleWidth      =   3435
      TabIndex        =   3
      Top             =   1320
      Width           =   3500
   End
   Begin VB.CommandButton Command3 
      Caption         =   "退出"
      Height          =   600
      Left            =   9000
      TabIndex        =   2
      Top             =   6960
      Width           =   1600
   End
   Begin VB.CommandButton Command2 
      Caption         =   "返回首界面"
      Height          =   600
      Left            =   5040
      TabIndex        =   1
      Top             =   6960
      Width           =   1600
   End
   Begin VB.CommandButton Command1 
      Caption         =   "输入矩阵X"
      Height          =   600
      Left            =   1200
      TabIndex        =   0
      Top             =   5760
      Width           =   1600
   End
   Begin VB.Label Label3 
      BackColor       =   &H00FFC0C0&
      Caption         =   "乘积矩阵Z"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   435
      Left            =   9000
      TabIndex        =   9
      Top             =   480
      Width           =   1440
   End
   Begin VB.Label Label2 
      BackColor       =   &H00FFC0C0&
      Caption         =   "矩阵Y"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   435
      Left            =   5400
      TabIndex        =   8
      Top             =   480
      Width           =   840
   End
   Begin VB.Label Label1 
      BackColor       =   &H00FFC0C0&
      Caption         =   "矩阵X"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   555
      Left            =   1560
      TabIndex        =   7
      Top             =   480
      Width           =   720
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
 Dim x() As Single
 Dim y() As Single
 Dim z() As Single
 Dim m As Single
 Dim n As Single
 Dim p As Single
 Dim n1 As Single
Private Sub Command1_Click()
  m = Val(InputBox("请输入矩阵X的行数", ""))
   If m = Val("") Then
    MsgBox "行列不能为零或空,请正确输入行列数"   '判断行列输入是否正确
   Exit Sub
   End If
  If m - Int(m) <> 0 Then
    MsgBox "行数为整数,请正确输入"
  Exit Sub
  End If
   
  n = Val(InputBox("请输入矩阵X的列数", ""))
   If Val(n) = Val("") Then
    MsgBox "行列不能为零或空,请正确输入行列数"   '判断行列输入是否正确
    Exit Sub
   End If
   If n - Int(n) <> 0 Then
    MsgBox "列数为整数,请正确输入"
    Exit Sub
   End If
  If m <= 0 Or n <= 0 Then
    MsgBox "行列应该大于零,请重新输入"              '判断行列输入是否正确
    Exit Sub
  End If
  
  ReDim x(m, n)
  For i = 1 To m
   For j = 1 To n
   x(i, j) = Val(InputBox("输入矩阵x (" & i & "," & j & ") 的值"))
   Next j
  Next i
 
  For i = 1 To m
   For j = 1 To n
    Picture2.Print Space(2); Format(x(i, j), "0.000");    '输出原矩阵
   Next j
  Picture2.Print
  Next i
  Command1.Enabled = False
  Command2.Enabled = True
  Command6.Enabled = True
End Sub

Private Sub Command2_Click()
 Form3.Show
 Form1.Hide                                    '返回开始界面
End Sub

Private Sub Command3_Click()
 End
End Sub

Private Sub Command4_Click()
 Picture1.Cls
 Picture2.Cls
 Picture3.Cls
 Command1.Enabled = True


End Sub

Private Sub Command5_Click()
  ReDim z(m, p)
  For i = 1 To m
   For q = 1 To p
     z(i, q) = 0
    For j = 1 To n1
    z(i, q) = z(i, q) + x(i, j) * y(j, q)    '把两矩阵相乘
    Next j
   Next q
  Next i
  
   For i = 1 To m
   For q = 1 To p
   Picture1.Print Space(2); Format(z(i, q), "0.000");
   Next q
  Picture1.Print
  Next i
  Command1.Enabled = False
  Command6.Enabled = False
  Command5.Enabled = False
End Sub

Private Sub Command6_Click()
  n1 = Val(InputBox("请输入矩阵Y的行数", ""))
    If n1 = Val("") Then
      MsgBox "行列不能为零或空,请正确输入行列数"         '判断行列输入是否正确
      Exit Sub
    End If
    If n1 - Int(n1) <> 0 Then
      MsgBox "行数为整数,请正确输入"
      Exit Sub
    End If
  
  p = Val(InputBox("请输入矩阵Y的列数", ""))
  If p = Val("") Then
    MsgBox "行列不能为零或空,请正确输入行列数"           '判断行列输入是否正确
    Exit Sub
  End If
  If p - Int(p) <> 0 Then
      MsgBox "列数为整数,请正确输入"
      Exit Sub
  End If
  
  If m <= 0 Or n <= 0 Then
  MsgBox "行列应大于零,请重新输入"
  Exit Sub
  End If
  
If n1 <> n Then
   MsgBox "行列不符合相乘法则,请重新输入"              '判断行列输入是否正确
   
Else
  ReDim y(n1, p)
  For j = 1 To n1
   For q = 1 To p
   y(j, q) = Val(InputBox("输入矩阵y (" & j & "," & q & ") 的值"))
   Next q
  Next j
  For j = 1 To n1
   For q = 1 To p
   Picture3.Print Space(2); Format(y(j, q), "0.000");  '输出转置后矩阵
   Next q
   Picture3.Print
  Next j
End If
Command5.Enabled = True
Command6.Enabled = False
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -