📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
ClientHeight = 6555
ClientLeft = 60
ClientTop = 345
ClientWidth = 7965
LinkTopic = "Form1"
ScaleHeight = 6555
ScaleWidth = 7965
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text11
Height = 855
Left = 240
TabIndex = 22
Text = "拉格朗日:y值"
Top = 4440
Width = 3855
End
Begin VB.TextBox Text10
Height = 855
Left = 240
TabIndex = 21
Text = "牛顿:y值"
Top = 3480
Width = 3855
End
Begin VB.TextBox Text9
Height = 1095
Left = 5640
TabIndex = 17
Text = "3"
Top = 720
Width = 2295
End
Begin VB.TextBox Text8
Height = 615
Left = 3120
TabIndex = 15
Text = "10"
Top = 2640
Width = 1455
End
Begin VB.TextBox Text7
Height = 615
Left = 960
TabIndex = 13
Text = "6"
Top = 2640
Width = 1455
End
Begin VB.CommandButton Command1
Caption = "计算对应的y值和公式"
Height = 615
Left = 360
TabIndex = 12
Top = 5400
Width = 3495
End
Begin VB.TextBox Text6
Height = 615
Left = 3120
TabIndex = 5
Text = "-2"
Top = 1800
Width = 1455
End
Begin VB.TextBox Text5
Height = 615
Left = 960
TabIndex = 4
Text = "3"
Top = 1800
Width = 1455
End
Begin VB.TextBox Text4
Height = 615
Left = 3120
TabIndex = 3
Text = "2"
Top = 960
Width = 1455
End
Begin VB.TextBox Text3
Height = 615
Left = 960
TabIndex = 2
Text = "0"
Top = 960
Width = 1455
End
Begin VB.TextBox Text2
Height = 615
Left = 3120
TabIndex = 1
Text = "-1"
Top = 120
Width = 1455
End
Begin VB.TextBox Text1
Height = 615
Left = 960
TabIndex = 0
Text = "-3"
Top = 120
Width = 1455
End
Begin VB.Label Label11
Caption = "y3"
Height = 855
Left = 2520
TabIndex = 20
Top = 2640
Width = 615
End
Begin VB.Label Label10
Caption = "x3"
Height = 735
Left = 360
TabIndex = 19
Top = 2640
Width = 495
End
Begin VB.Label Label9
Caption = "在此输入x值"
Height = 1215
Left = 5160
TabIndex = 18
Top = 720
Width = 495
End
Begin VB.Label Label8
Caption = "拉格朗日三次对应的y值"
Height = 975
Left = 4320
TabIndex = 16
Top = 4440
Width = 1335
End
Begin VB.Label Label7
Caption = "牛顿三次插值对应的y值"
Height = 855
Left = 4440
TabIndex = 14
Top = 3480
Width = 1335
End
Begin VB.Label Label6
Caption = "y2"
Height = 495
Left = 2520
TabIndex = 11
Top = 1800
Width = 495
End
Begin VB.Label Label5
Caption = "x2"
Height = 495
Left = 360
TabIndex = 10
Top = 1920
Width = 495
End
Begin VB.Label Label4
Caption = "y1"
Height = 495
Left = 2640
TabIndex = 9
Top = 1080
Width = 495
End
Begin VB.Label Label3
Caption = "x1"
Height = 495
Left = 360
TabIndex = 8
Top = 960
Width = 495
End
Begin VB.Label Label2
Caption = "y0"
Height = 495
Left = 2520
TabIndex = 7
Top = 240
Width = 495
End
Begin VB.Label Label1
Caption = "x0"
Height = 495
Left = 360
TabIndex = 6
Top = 240
Width = 495
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 x3 As Double
Dim y0 As Double
Dim y1 As Double
Dim y2 As Double
Dim y3 As Double
Dim x As Double
Dim y As Double
Dim t01 As Double
Dim t12 As Double
Dim t23 As Double
Dim t012 As Double
Dim t123 As Double
Dim t0123 As Double
Dim s0 As Double
Dim s1 As Double
Dim s2 As Double
Dim s3 As Double
x0 = Text1.Text
y0 = Text2.Text
x1 = Text3.Text
y1 = Text4.Text
x2 = Text5.Text
y2 = Text6.Text
x3 = Text7.Text
y3 = Text8.Text
x = Text9.Text
t01 = (y0 - y1) / (x0 - x1)
t12 = (y1 - y2) / (x1 - x2)
t23 = (y2 - y3) / (x2 - x3)
t012 = (t01 - t12) / (x0 - x2)
t123 = (t12 - t23) / (x1 - x3)
t0123 = (t012 - t123) / (x0 - x3)
y = y0 + (x - x0) * t01 + (x - x0) * (x - x1) * t012 + (x - x0) * (x - x1) * (x - x2) * t0123
Text10.Text = CStr(y)
s0 = (x - x1) * (x - x2) * (x - x3) / ((x0 - x1) * (x0 - x2) * (x0 - x3))
s1 = (x - x0) * (x - x2) * (x - x3) / ((x1 - x0) * (x1 - x2) * (x1 - x3))
s2 = (x - x0) * (x - x1) * (x - x3) / ((x2 - x0) * (x2 - x1) * (x2 - x3))
s3 = (x - x0) * (x - x1) * (x - x2) / ((x3 - x1) * (x3 - x2) * (x3 - x0))
'utgpigtiuiyohyoih8tg76pf87juhi
y = s0 * y0 + s1 * y1 + s2 * y2 + s3 * y3
Text11.Text = ccstr(y)
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 + -