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

📄 form1.frm

📁 本源码是利用VB编写的加边法矩阵求逆
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   7830
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   12885
   LinkTopic       =   "Form1"
   ScaleHeight     =   7830
   ScaleWidth      =   12885
   StartUpPosition =   3  '窗口缺省
   Begin VB.TextBox Text3 
      Height          =   615
      Index           =   0
      Left            =   6600
      TabIndex        =   5
      TabStop         =   0   'False
      Top             =   240
      Width           =   1335
   End
   Begin VB.CommandButton Command2 
      Caption         =   "矩阵求逆"
      Height          =   615
      Left            =   5160
      TabIndex        =   4
      TabStop         =   0   'False
      Top             =   240
      Width           =   1215
   End
   Begin VB.TextBox Text2 
      Height          =   495
      Index           =   0
      Left            =   1920
      TabIndex        =   1
      Top             =   1320
      Width           =   495
   End
   Begin VB.TextBox Text1 
      Height          =   615
      Left            =   1920
      TabIndex        =   0
      Top             =   360
      Width           =   975
   End
   Begin VB.Label Label2 
      Caption         =   "请输入矩阵系数:"
      Height          =   615
      Left            =   240
      TabIndex        =   3
      Top             =   1440
      Width           =   1455
   End
   Begin VB.Label Label1 
      Caption         =   "请输入矩阵阶数:"
      Height          =   615
      Left            =   240
      TabIndex        =   2
      Top             =   480
      Width           =   1815
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
 Option Base 1
Private Sub Command2_Click()
Dim A(), B()
Dim m, n, i, j, k, h
  m = Val(Me.Text1.Text)
  n = Val(Text1.Text) * Val(Text1.Text)
  ReDim A(1 To m, 1 To m)
  ReDim B(1 To m, 1 To m)
 '填写矩阵的每一个系数
 For k = 0 To n - 1
  If Me.Text2(k).Text = "" Then
    MsgBox "请输入完整的矩阵系数!", "输入系数!"
    Text2(k).SetFocus
  End If
 Next k
   '给矩阵的每一个元素赋值
  For h = 0 To n - 1
    i = Int(h / m) + 1
    j = (h + m) Mod m + 1
    A(i, j) = Val(Text2(h).Text)
  Next h
  A(1, 1) = 1 / A(1, 1)
  
'根据加边法求取逆矩阵
  For k = 1 To m - 1
   For j = 1 To k
    B(k + 1, j) = 0
    
    For i = 1 To k
      B(k + 1, j) = B(k + 1, j) + A(k + 1, i) * A(i, j)
    Next i
    Next j
    B(k + 1, k + 1) = A(k + 1, k + 1)
    For j = 1 To k
      B(k + 1, k + 1) = B(k + 1, k + 1) - B(k + 1, j) * A(j, k + 1)
    Next j
    A(k + 1, k + 1) = 1 / B(k + 1, k + 1)
    For i = 1 To k
     B(k + 1, i) = 0
     B(i, k + 1) = 0
     For j = 1 To k
       B(k + 1, i) = B(k + 1, i) - A(k + 1, j) * A(j, i)
       B(i, k + 1) = B(i, k + 1) - A(i, j) * A(j, k + 1)
     Next j
     
     B(k + 1, i) = B(k + 1, i) * A(k + 1, k + 1)
     B(i, k + 1) = B(i, k + 1) * A(k + 1, k + 1)
     Next i
     For i = 1 To k
       A(k + 1, i) = B(k + 1, i)
       A(i, k + 1) = B(i, k + 1)
     Next i
     For i = 1 To k
       For j = 1 To k
       B(i, j) = A(i, j) + B(i, k + 1) * B(k + 1, j) / A(k + 1, k + 1)
       A(i, j) = B(i, j)
       Next j
      Next i
    Next k
 '显示text3用来放置逆矩阵
 For i = 1 To n - 1
        Load Text3(i)
          With Text3(i)
          If i Mod j = 0 Then
           .Top = Text3(i - 1).Top + .Height
           .Left = Text3(i - j).Left
           .Visible = True
         
         Else
           .Top = Text3(i - 1).Top
           .Left = Text3(i - 1).Left + .Width
           .Visible = True
         End If
          End With
    Next i
 '在text3中打印求逆结果
    
    For h = 0 To n - 1
       i = Int(h / m) + 1
       j = (h + m) Mod m + 1
       Me.Text3(h).Text = Str(A(i, j))
      
    
    Next h
 
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
  Dim i, j, k, n As Integer
  If KeyAscii = 13 Then
  j = Val(Text1.Text)
   n = Val(Text1.Text) * Val(Text1.Text)
    For i = 1 To n - 1
        Load Text2(i)
          With Text2(i)
          If i Mod j = 0 Then
           .Top = Text2(i - 1).Top + .Height
           .Left = Text2(i - j).Left
           .Visible = True
         
         Else
           .Top = Text2(i - 1).Top
           .Left = Text2(i - 1).Left + .Width
           .Visible = True
         End If
          End With
    Next i
  End If
End Sub

⌨️ 快捷键说明

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