📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 5205
ClientLeft = 60
ClientTop = 345
ClientWidth = 6885
LinkTopic = "Form1"
ScaleHeight = 5205
ScaleWidth = 6885
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text7
Height = 495
Left = 3240
TabIndex = 7
Text = "原函数为y=exp(-x)"
Top = 240
Width = 3615
End
Begin VB.CommandButton Command1
Caption = "计算公式和对应的y值"
Height = 3015
Left = 3360
TabIndex = 6
Top = 1800
Width = 495
End
Begin VB.TextBox Text6
Height = 855
Left = 4080
TabIndex = 5
Top = 2760
Width = 2775
End
Begin VB.TextBox Text5
Height = 855
Left = 4080
TabIndex = 4
Top = 1440
Width = 2775
End
Begin VB.TextBox Text4
Height = 855
Left = 360
TabIndex = 3
Top = 3600
Width = 2535
End
Begin VB.TextBox Text3
Height = 855
Left = 360
TabIndex = 2
Top = 2280
Width = 2415
End
Begin VB.TextBox Text2
Height = 855
Left = 360
TabIndex = 1
Top = 1200
Width = 2415
End
Begin VB.TextBox Text1
Height = 855
Left = 360
TabIndex = 0
Top = 120
Width = 2415
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim x0 As Double
Dim x1 As Double
Dim x2 As Double
Dim y0 As Double
Dim y1 As Double
Dim y2 As Double
Dim x As Double
Dim y As Double
Dim s0 As String
Dim s1 As String
Dim s2 As String
Dim t0 As Double
Dim t1 As Double
Dim t2 As Double
x0 = CDbl(Text1.Text)
x1 = CDbl(Text2.Text)
x2 = CDbl(Text3.Text)
x = CDbl(Text4.Text)
y1 = Exp(-x1)
y2 = Exp(-x2)
y0 = Exp(-x0)
t0 = (x - x1) * (x - x2) / ((x0 - x1) * (x0 - x2))
t1 = (x - x0) * (x - x2) / ((x1 - x0) * (x1 - x2))
t2 = (x - x0) * (x - x1) / ((x2 - x0) * (x2 - x1))
y = y1 * t1 + y2 * t2 + y0 * t0
Text5.Text = ccstr(y)
s0 = "(x-" + ccstr(x1) + ")" + "*" + "(x-" + ccstr(x2) + ")" + "/(" + ccstr((x0 - x1) * (x0 - x2)) + ")"
s1 = "(x-" + ccstr(x2) + ")" + "*" + "(x-" + ccstr(x0) + ")" + "/(" + ccstr((x1 - x2) * (x1 - x0)) + ")"
s2 = "(x-" + ccstr(x1) + ")" + "*" + "(x-" + ccstr(x0) + ")" + "/(" + ccstr((x2 - x1) * (x2 - x0)) + ")"
Text6.Text = s0 + "*" + ccstr(y0) + "+" + s1 + "*" + ccstr(y1) + s2 + "*" + ccstr(y2)
End Sub
Function ccstr(a As Double)
If 0 < a And a < 1 Then ccstr = "0" + CStr(a) '特殊情况 为-1到1 之间的数字
If -1 < a And a < 0 Then ccstr = "-0" + CStr(Abs(a))
If CStr(a) = "0" Then ccstr = "0"
If Abs(a) >= 1 Then ccstr = CStr(a)
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -