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

📄 常微分~2.frm

📁 以前学计算方法时,根据老师的要求做的一些基础实验VB.
💻 FRM
字号:
VERSION 5.00
Begin VB.Form 常微分方程 
   BackColor       =   &H00FFFF80&
   Caption         =   "Form1"
   ClientHeight    =   8355
   ClientLeft      =   135
   ClientTop       =   405
   ClientWidth     =   12195
   LinkTopic       =   "Form1"
   ScaleHeight     =   8355
   ScaleWidth      =   12195
   StartUpPosition =   3  '窗口缺省
   Begin VB.ListBox List6 
      Height          =   240
      Left            =   4800
      TabIndex        =   12
      Top             =   6960
      Width           =   2412
   End
   Begin VB.ListBox List5 
      Height          =   240
      Left            =   2160
      TabIndex        =   11
      Top             =   6960
      Width           =   1932
   End
   Begin VB.ListBox List4 
      Height          =   240
      Left            =   4800
      TabIndex        =   10
      Top             =   6600
      Width           =   2412
   End
   Begin VB.ListBox List3 
      Height          =   240
      Left            =   2160
      TabIndex        =   9
      Top             =   6600
      Width           =   1932
   End
   Begin VB.ListBox List2 
      Height          =   240
      Left            =   4800
      TabIndex        =   8
      Top             =   6240
      Width           =   2412
   End
   Begin VB.ListBox List1 
      Height          =   240
      Left            =   2160
      TabIndex        =   7
      Top             =   6240
      Width           =   1932
   End
   Begin VB.CommandButton Command6 
      Caption         =   "退出"
      Height          =   612
      Left            =   120
      TabIndex        =   6
      Top             =   4800
      Width           =   1452
   End
   Begin VB.CommandButton Command5 
      Caption         =   "重新运行"
      Height          =   612
      Left            =   120
      TabIndex        =   5
      Top             =   3840
      Width           =   1452
   End
   Begin VB.CommandButton Command4 
      Caption         =   "四阶龙库塔法"
      Height          =   612
      Left            =   120
      TabIndex        =   4
      Top             =   3000
      Width           =   1452
   End
   Begin VB.CommandButton Command3 
      Caption         =   "改进欧拉法"
      Height          =   612
      Left            =   120
      TabIndex        =   3
      Top             =   2160
      Width           =   1452
   End
   Begin VB.CommandButton Command2 
      Caption         =   "欧拉法"
      Height          =   612
      Left            =   120
      TabIndex        =   2
      Top             =   1320
      Width           =   1452
   End
   Begin VB.CommandButton Command1 
      Caption         =   "产生坐标系"
      Height          =   612
      Left            =   120
      TabIndex        =   1
      Top             =   480
      Width           =   1452
   End
   Begin VB.PictureBox Picture1 
      BackColor       =   &H00FFFFC0&
      Height          =   5172
      Left            =   1920
      ScaleHeight     =   5115
      ScaleWidth      =   7755
      TabIndex        =   0
      Top             =   360
      Width           =   7812
   End
   Begin VB.Label Label5 
      Caption         =   "y1"
      Height          =   252
      Left            =   5400
      TabIndex        =   17
      Top             =   5880
      Width           =   732
   End
   Begin VB.Label Label4 
      Caption         =   "x1"
      Height          =   252
      Left            =   2640
      TabIndex        =   16
      Top             =   5880
      Width           =   732
   End
   Begin VB.Label Label3 
      Caption         =   "四阶龙库塔法:"
      Height          =   252
      Left            =   600
      TabIndex        =   15
      Top             =   6960
      Width           =   1212
   End
   Begin VB.Label Label2 
      Caption         =   "改进欧拉法"
      Height          =   252
      Left            =   600
      TabIndex        =   14
      Top             =   6600
      Width           =   1212
   End
   Begin VB.Label Label1 
      Caption         =   "欧拉法"
      Height          =   252
      Left            =   600
      TabIndex        =   13
      Top             =   6228
      Width           =   1212
   End
End
Attribute VB_Name = "常微分方程"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Command1.Enabled = False
Call zuobiao
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
End Sub

Private Function zuobiao()
Picture1.DrawWidth = 2
Picture1.ScaleMode = 6
Picture1.Line (8, 8)-(8, 80), vbRed
Picture1.Line (8, 80)-(130, 80), vbRed
Picture1.Line (7, 11)-(8, 8), vbRed
Picture1.Line (9, 11)-(8, 8), vbRed
Picture1.Line (128, 79)-(130, 80), vbRed
Picture1.Line (128, 81)-(130, 80), vbRed
Picture1.ForeColor = vbRed
Picture1.FontBold = True
Picture1.FontSize = 18
Picture1.CurrentX = 3: Picture1.CurrentY = 6
Picture1.Print "Y"
Picture1.CurrentX = 3: Picture1.CurrentY = 80
Picture1.Print "O"
Picture1.CurrentX = 128: Picture1.CurrentY = 82
Picture1.Print "X"
End Function

Private Sub Command2_Click()
Command2.Enabled = False
Call euler
End Sub

Private Sub Command3_Click()
Command3.Enabled = False
Call improveeuler
End Sub

Private Sub Command4_Click()
Command4.Enabled = False
Call runge_kutta
End Sub

Private Sub Command5_Click()
Picture1.Cls
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = True
End Sub
Private Sub Command6_Click()
常微分方程.Hide
Form1.Show
End Sub
Private Sub form_load()
Form1.Left = 200
Form1.Top = 250
End Sub
Public Function delay(ByVal m As Integer)
Dim i%, j%
For i = 0 To 9999
  For j = 0 To m
  Next
Next
End Function
Public Function euler()
Dim x0#, y0#, n%, N1%, h#, x1#, y1#, Y#, k#
x0 = InputBox("请输入x0:", "直接欧拉法", 0)
y0 = InputBox("请输入y0:", "直接欧拉法", 1)
h = InputBox("请输入步长h:", "直接欧拉法", 0.1, 0.01)
n = 1
For x = 0 To 2 Step h
x1 = x0 + h
y1 = y0 + h * (-y0 - x0 * y0 ^ 2)
CurrentX = 8 + 30 * (x0 + h): CurrentY = 80
Picture1.Line (x0 * 30 + 8, 80 - y0 * 30)-(x1 * 30 + 8, 80 - y1 * 30), vbYellow

Call delay(100)
List1.AddItem (x1): List2.AddItem (y1)
n = n + 1
x0 = x1
y0 = y1
Next
End Function
Public Function improveeuler()
Dim x0#, y0#, yp#, yc#, n%, N1%, h#, x1#, y1#
x0 = InputBox("请输入x0:", "改进欧拉法", 0)
y0 = InputBox("请输入y0:", "改进欧拉法", 1)
h = InputBox("请输入步长h:", "改进欧拉法", 0.1, 0.01)
n = 1
For x = 0 To 2 Step h
x1 = x0 + h
yp = y0 + h * (-y0 - x0 * y0 ^ 2)
yc = y0 + h * (-yp - x1 * yp ^ 2)
y1 = (yp + yc) / 2
CurrentX = 8 + 30 * (x0 + h): CurrentY = 80
Picture1.Line (x0 * 30 + 8, 80 - y0 * 30)-(x1 * 30 + 8, 80 - y1 * 30), vbBlue

Call delay(100)
List3.AddItem (x1): List4.AddItem (y1)
n = n + 1
x0 = x1
y0 = y1
Next
End Function
Public Function runge_kutta()
Dim x0#, y0#, k1#, k2#, k3#, k4#, n%, N1%, h#, x1#, y1#
x0 = InputBox("请输入x0:", "四阶龙库塔", 0)
y0 = InputBox("请输入y0:", "四阶龙库塔", 1)
h = InputBox("请输入步长h:", "四阶龙库塔", 0.1, 0.01)
n = 1
For x = 0 To 2 Step h
x1 = x0 + h
k1 = -y0 - x0 * y0 * y0
k2 = -(y0 + k1 * h / 2) - (x0 + h / 2) * (y0 + k1 * h / 2) ^ 2
k3 = -(y0 + k2 * h / 2) - (x0 + h / 2) * (y0 + k2 * h / 2) ^ 2
k2 = -(y0 + k3 * h / 2) - x1 * (y0 + k3 * h / 2) ^ 2
y1 = y0 + (k1 + 2 * k2 + 2 * k3 + k4) * h / 6
CurrentX = 8 + 30 * (x0 + h): CurrentY = 80
Picture1.Line (x0 * 30 + 8, 80 - y0 * 30)-(x1 * 30 + 8, 80 - y1 * 30), vbRed

Call delay(100)
List5.AddItem (x1): List6.AddItem (y1)
n = n + 1
x0 = x1
y0 = y1
Next
End Function

⌨️ 快捷键说明

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