📄 方法2.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form 方法2
Caption = "乔列斯基分解法"
ClientHeight = 7860
ClientLeft = 60
ClientTop = 450
ClientWidth = 10275
Icon = "方法2.frx":0000
LinkTopic = "Form2"
Picture = "方法2.frx":0442
ScaleHeight = 7860
ScaleWidth = 10275
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command3
BackColor = &H0080FF80&
Caption = "返回主窗口"
DownPicture = "方法2.frx":2613D
DragIcon = "方法2.frx":2657F
Height = 615
Left = 8880
MouseIcon = "方法2.frx":269C1
MousePointer = 1 'Arrow
OLEDropMode = 1 'Manual
Picture = "方法2.frx":26E03
Style = 1 'Graphical
TabIndex = 9
Top = 7200
Width = 1335
End
Begin VB.Timer Timer1
Interval = 20
Left = 840
Top = 1920
End
Begin VB.PictureBox Picture1
BackColor = &H0080FFFF&
Height = 2535
Left = 7080
ScaleHeight = 2475
ScaleWidth = 2955
TabIndex = 6
Top = 840
Width = 3015
End
Begin VB.PictureBox Picture2
BackColor = &H0080FF80&
Height = 2295
Left = 6960
ScaleHeight = 2235
ScaleWidth = 3075
TabIndex = 5
Top = 4560
Width = 3135
End
Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1
Height = 2535
Left = 120
TabIndex = 4
Top = 4680
Width = 6495
_ExtentX = 11456
_ExtentY = 4471
_Version = 393216
Rows = 15
Cols = 15
BackColor = 16776960
FormatString = "^ 序列|^ x1|^ x2|^ x3|^ x4|^ x5|^ x6|^ x7|^ x8|^ x9|^ x10|^ b"
End
Begin VB.CommandButton Command2
BackColor = &H00FFFF00&
Caption = "LU法解方程组"
Height = 735
Left = 2400
Style = 1 'Graphical
TabIndex = 3
Top = 3600
Width = 1455
End
Begin VB.CommandButton Command1
BackColor = &H008080FF&
Caption = "打开方程组"
DownPicture = "方法2.frx":27245
Height = 735
Left = 360
Style = 1 'Graphical
TabIndex = 2
Top = 3600
Width = 1335
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 240
Top = 1920
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.TextBox Text1
BackColor = &H00C0FFC0&
Height = 1815
Left = 4200
MultiLine = -1 'True
TabIndex = 0
Top = 2640
Width = 2175
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "L'分解"
BeginProperty Font
Name = "宋体"
Size = 21.75
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 495
Left = 7920
TabIndex = 8
Top = 3960
Width = 1455
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "L分解"
BeginProperty Font
Name = "宋体"
Size = 21.75
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H0000FFFF&
Height = 435
Left = 7920
TabIndex = 7
Top = 360
Width = 1140
End
Begin VB.Image Image4
Height = 15
Left = 2880
Top = 3240
Width = 135
End
Begin VB.Image Image3
Appearance = 0 'Flat
Height = 1155
Left = 2640
Picture = "方法2.frx":4683E
Top = 600
Visible = 0 'False
Width = 1155
End
Begin VB.Image Image2
Appearance = 0 'Flat
Height = 1155
Left = 1320
Picture = "方法2.frx":474C8
Top = 600
Visible = 0 'False
Width = 1155
End
Begin VB.Image Image1
Height = 1155
Left = 0
Picture = "方法2.frx":48152
Top = 600
Width = 1155
End
Begin VB.Label Label3
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "结果输出"
BeginProperty Font
Name = "隶书"
Size = 21.75
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000FF&
Height = 435
Left = 4440
TabIndex = 1
Top = 2040
Width = 1860
End
End
Attribute VB_Name = "方法2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim A(20, 20) As Single, B() As Single, X() As Single, p() As Single, q() As Single
Dim i As Integer, N As Integer, j As Integer
Private Sub Command1_Click()
Dim FileName As String
Dim Astr As String
On Error GoTo errhandle
CommonDialog1.InitDir = App.Path '设置初始路径 数据导入
CommonDialog1.FileName = "" '清除文件名
CommonDialog1.ShowOpen '显示“打开”对话框
FileName = CommonDialog1.FileName '保存文件名
If Len(CommonDialog1.FileName) > 0 Then
'File = FreeFile() '获得可用文件号
Open FileName For Input As #1 '打开文件
End If
i = 0: N = 0: j = 0: Dim Line1 As String
MousePointer = 11
Do While EOF(1) = False
N = N + 1
Line Input #1, Line1
Loop
ReDim B(N): ReDim X(N, N)
MSFlexGrid1.Cols = N + 2: MSFlexGrid1.Rows = N + 1
Close #1
Dim Forstr As String
Forstr = "序列"
For i = 1 To N
Forstr = Forstr & "|^ x" & i
MSFlexGrid1.TextMatrix(i, 0) = i
Next i
Forstr = Forstr & "|^ b"
MSFlexGrid1.FormatString = Forstr
Open FileName For Input As #2 '打开文件
Do While EOF(2) = False
j = j + 1
For i = 1 To N
Input #2, Astr ' 分别输入各数据
A(j, i) = Astr
MSFlexGrid1.TextMatrix(j, i) = Astr
Next i
Input #2, Astr
B(j) = Astr
MSFlexGrid1.TextMatrix(j, N + 1) = Astr
Loop
Close #2
errhandle:
MousePointer = 0
Exit Sub
MousePointer = 0
End Sub
Private Sub Command2_Click()
Dim k%, t As Single, s As Single, g As Single, Sum As Single, w As Single
ReDim X(N, N)
X(1, 1) = (A(1, 1)) ^ (1 / 2)
For j = 2 To N
X(j, 1) = A(j, 1) / X(1, 1)
Next j
For j = 2 To N
s = 0: t = 0
For k = 1 To j - 1
s = s + (X(j, k)) ^ 2
Next k
X(j, j) = (A(j, j) - s) ^ (1 / 2)
For i = j + 1 To N
For k = 1 To j - 1
t = t + X(i, k) * X(j, k)
Next k
X(i, j) = (A(i, j) - t) / X(j, j)
Next i
Next j
For i = 1 To N
For j = 1 To N
Picture1.Print X(i, j),
Next j
Picture1.Print
Next i '显示L矩阵
ReDim p(N)
p(1) = B(1) / X(1, 1)
For i = 2 To N
For k = 1 To i - 1
g = g + X(i, k) * p(k)
Next k
p(i) = (B(i) - g) / X(i, i)
Next i
ReDim q(N)
For i = 1 To N
For j = 1 To i - 1
w = X(i, j)
X(i, j) = X(j, i)
X(j, i) = w
Next j
Next i '矩阵转置
For i = 1 To N
For j = 1 To N
Picture2.Print X(i, j),
Next j
Picture2.Print
Next i '显示L'矩阵
q(N) = p(N) / X(N, N)
For i = N - 1 To 1 Step -1
Sum = 0
For j = i + 1 To N
Sum = Sum + X(i, j) * q(j)
Next j
q(i) = (p(i) - Sum) / X(i, i)
Next i
For i = 1 To N
Text1.Text = Text1.Text & "x" & i & "=" & q(i) & vbCrLf
Next i
End Sub
Private Sub Command3_Click()
方法2.Hide
主窗口.Show
End Sub
Private Sub Timer1_Timer()
Static ImaBmp As Integer
Image1.Move Image1.Left + 20, Image1.Top - 5
If Image1.Top <= 0 Then
Image1.Left = 0
Image1.Top = 1320
End If
If ImaBmp Then
Image1.Picture = Image3.Picture
Else
Image1.Picture = Image2.Picture
End If
ImaBmp = Not ImaBmp
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -