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

📄 lu分解法.frm

📁 完整的数值模拟软件
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form15 
   BackColor       =   &H00C0C0C0&
   Caption         =   "LU分解法"
   ClientHeight    =   7500
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   12540
   LinkTopic       =   "Form15"
   ScaleHeight     =   7500
   ScaleWidth      =   12540
   StartUpPosition =   3  '窗口缺省
   Begin VB.PictureBox Picture2 
      BackColor       =   &H00FFFFFF&
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   4815
      Left            =   5760
      ScaleHeight     =   4755
      ScaleWidth      =   6075
      TabIndex        =   4
      Top             =   2160
      Width           =   6135
   End
   Begin VB.PictureBox Picture1 
      BackColor       =   &H00FFFFFF&
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   3495
      Left            =   240
      ScaleHeight     =   3435
      ScaleWidth      =   4875
      TabIndex        =   2
      Top             =   2160
      Width           =   4935
   End
   Begin VB.CommandButton Command1 
      Caption         =   "LU分解法"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   4320
      TabIndex        =   0
      Top             =   480
      Width           =   2175
   End
   Begin VB.Label Label2 
      BackColor       =   &H00C0C0C0&
      Caption         =   "运算结果"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   8040
      TabIndex        =   3
      Top             =   1560
      Width           =   1935
   End
   Begin VB.Label Label1 
      BackColor       =   &H00C0C0C0&
      Caption         =   "方程组的系数矩阵"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   1080
      TabIndex        =   1
      Top             =   1560
      Width           =   2415
   End
End
Attribute VB_Name = "Form15"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
    Dim a(), b(), X(), Y(), l(), u() As Single
     
      n = InputBox("输入方程组的个数n", , , 100, 100)
      ReDim X(n), a(n, n), l(n, n), u(n, n), b(n), Y(n)
      
    Picture1.Cls
    
     For i = 1 To n
       For j = 1 To n
          a(i, j) = InputBox("输入a(" & i & "," & j & ")的值", , , 100, 100)
          Picture1.Print a(i, j),
       Next j
       
          b(i) = InputBox("输入b(" & i & ")的值", , , 100, 100)
           Picture1.Print b(i)
    Next i
    
    '分解为L,U矩阵
    For i = 1 To n
       
         For j = 1 To i - 1
             Sum = a(i, j)
                
                For k = 1 To j - 1
                     Sum = Sum - a(i, k) * a(k, j)
                Next k
             a(i, j) = Sum / a(j, j)
         Next j
        
         For j = 1 To i
            Sum = a(j, i)
                For k = 1 To j - 1
                    Sum = Sum - a(j, k) * a(k, i)
                Next k
             a(j, i) = Sum
           '   u(j, i) = a(j, i)
           '  Picture2.Print u(j, i)
         Next j
     Next i
     
   '表示为L矩阵
   Picture2.Cls
    Picture2.Print "L矩阵为"
    Picture2.Print
      For i = 1 To n
       For j = 1 To n
          If i = j Then
              l(i, j) = 1
          Else
            If i < j Then
                l(i, j) = 0
             Else
                l(i, j) = a(i, j)
 
            End If
          End If
           l(i, j) = Int(l(i, j) * 10000) / 10000
          Picture2.Print l(i, j),
      Next j
          Picture2.Print
   Next i
     ms = MsgBox("按任意键继续")
     
   '表示为U矩阵
   Picture2.Print "U矩阵为"
    Picture2.Print
    For i = 1 To n
       For j = 1 To n
          If i > j Then
              u(i, j) = 0
          ElseIf i <= j Then
               u(i, j) = a(i, j)
             
          End If
         u(i, j) = Int(u(i, j) * 10000) / 10000
          Picture2.Print u(i, j),
      Next j
          Picture2.Print
   Next i
   ms = MsgBox("按任意键继续")
      
 '求解Ly=b
  Picture2.Print "求解Ly=b"
    Y(n) = b(n)
    For i = 1 To n
       Sum = b(i)
       For k = 1 To i - 1
        Sum = Sum - a(i, k) * b(k)
        Next k
         b(i) = Sum
        Y(i) = b(i)
     Next i
      Picture2.Print
         For i = 1 To n
           Picture2.Print "  y(" + Str(i) + ")=  "; Int(Y(i) * 10000) / 10000
         Next i
     ms = MsgBox("按任意键继续")
  '求解Ux=y
   Picture2.Print "求解Ux=y"
     X(n) = b(n)
    For i = n To 1 Step -1
        Sum = b(i)
            For j = i + 1 To n
                Sum = Sum - a(i, j) * b(j)
            Next j
        b(i) = Sum / a(i, i)
        X(i) = b(i)
    Next i
        Picture2.Print
         For i = 1 To n
           Picture2.Print "    x(" + Str(i) + ")=  "; Int(X(i) * 10000) / 10000
         Next i
       
End Sub


⌨️ 快捷键说明

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