拉格朗日插值 VB 数学 数值分析 出什么问题了
PrivateSubCommand1_Click()Dimnihe_Parameters(2,8)AsDoubleDimA(8)AsDoubleDimB(8)AsDoub...
Private Sub Command1_Click()
Dim nihe_Parameters(2, 8) As Double
Dim A(8) As Double
Dim B(8) As Double
Dim chazhihou As Double
Dim INEdLagrn() As Double
Open "3.20.txt" For Input As #1
For j = 1 To 2
For i = 1 To num_point_nihe
Input #1, nihe_Parameters(j, i)
Next i
Next j
Close #1
For i = 1 To num_point_nihe
A(i) = nihe_Parameters(1, i)
B(i) = nihe_Parameters(2, i)
chazhihou = INEdLagrn(13, 0.05, 0, B(i), 0.65)
Next i
Text1.Text = chazhihou
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 模块名:InterpModule.bas
' 函数名:INEdLagrn
' 功能: 用拉格朗日插值公式进行一元全区间等距插值
' 参数: n - Integer型变量,给定结点的点数
' h - Integer型变量,等距结点的步长
' x0 - Double型变量,存放等距n个结点中第一个结点的值
' y - Double型一维数组,长度为n,存放给定的n个等距结点的函数值y(i),y(i) = f(x(i)), i=1,2,...,n
' t - Double型变量,存放指定的插值点的值
' 返回值:Double型,指定的查指点t的函数近似值f(t)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function INEdLagrn(n As Integer, h As Double, x0 As Double, y() As Double, t As Double) As Double
Dim i As Integer, j As Integer, k As Integer, m As Integer
Dim z As Double, s As Double, xi As Double, xj As Double
Dim p As Double, q As Double
' 初值
z = 0#
' 特例处理
If (n < 1) Then
INEdLagrn = z
Exit Function
End If
If (n = 1) Then
z = y(1)
INEdLagrn = z
Exit Function
End If
If (n = 2) Then
z = (y(2) * (t - x0) - y(1) * (t - x0 - h)) / h
INEdLagrn = z
Exit Function
End If
' 开始插值
If (t > x0) Then
p = (t - x0) / h
i = Int(p)
q = i
If (p > q) Then i = i + 1
Else
i = 0
End If
k = i - 4
If (k < 0) Then k = 0
m = i + 3
If (m > n - 1) Then m = n - 1
For i = k To m
s = 1#
xi = x0 + i * h
For j = k To m
If (j <> i) Then
xj = x0 + j * h
' 拉格朗日插值公式
s = s * (t - xj) / (xi - xj)
End If
Next j
z = z + s * y(i + 1)
Next i
' 返回结果
INEdLagrn = z
End Function 展开
Dim nihe_Parameters(2, 8) As Double
Dim A(8) As Double
Dim B(8) As Double
Dim chazhihou As Double
Dim INEdLagrn() As Double
Open "3.20.txt" For Input As #1
For j = 1 To 2
For i = 1 To num_point_nihe
Input #1, nihe_Parameters(j, i)
Next i
Next j
Close #1
For i = 1 To num_point_nihe
A(i) = nihe_Parameters(1, i)
B(i) = nihe_Parameters(2, i)
chazhihou = INEdLagrn(13, 0.05, 0, B(i), 0.65)
Next i
Text1.Text = chazhihou
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 模块名:InterpModule.bas
' 函数名:INEdLagrn
' 功能: 用拉格朗日插值公式进行一元全区间等距插值
' 参数: n - Integer型变量,给定结点的点数
' h - Integer型变量,等距结点的步长
' x0 - Double型变量,存放等距n个结点中第一个结点的值
' y - Double型一维数组,长度为n,存放给定的n个等距结点的函数值y(i),y(i) = f(x(i)), i=1,2,...,n
' t - Double型变量,存放指定的插值点的值
' 返回值:Double型,指定的查指点t的函数近似值f(t)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function INEdLagrn(n As Integer, h As Double, x0 As Double, y() As Double, t As Double) As Double
Dim i As Integer, j As Integer, k As Integer, m As Integer
Dim z As Double, s As Double, xi As Double, xj As Double
Dim p As Double, q As Double
' 初值
z = 0#
' 特例处理
If (n < 1) Then
INEdLagrn = z
Exit Function
End If
If (n = 1) Then
z = y(1)
INEdLagrn = z
Exit Function
End If
If (n = 2) Then
z = (y(2) * (t - x0) - y(1) * (t - x0 - h)) / h
INEdLagrn = z
Exit Function
End If
' 开始插值
If (t > x0) Then
p = (t - x0) / h
i = Int(p)
q = i
If (p > q) Then i = i + 1
Else
i = 0
End If
k = i - 4
If (k < 0) Then k = 0
m = i + 3
If (m > n - 1) Then m = n - 1
For i = k To m
s = 1#
xi = x0 + i * h
For j = k To m
If (j <> i) Then
xj = x0 + j * h
' 拉格朗日插值公式
s = s * (t - xj) / (xi - xj)
End If
Next j
z = z + s * y(i + 1)
Next i
' 返回结果
INEdLagrn = z
End Function 展开
1个回答
2014-08-04
展开全部
过程的简单调用的调试比较好搞,按F8逐语句运行,并监视关键变量值的变化,并配合在程序中使用debug.print语句,在立即窗口中打印变量当前值,添加关键变量到监视窗口,很快自己就可以搞定
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询