我最近遇到了一个我拥有的数据集的问题,因为它的“分辨率”太小了。数据集的特征是有一个最大值 (0),这实际上并不是它的最大值,因为所有数字都被归一化为在其“分辨率”内找到的更高数字,这基本上是“X”的“1 x 1 单位”柱子。Y 值始终类似于抛物线。
Y X
-34,32 -93
-16,56 -92
-10,04 -91
-6,03 -90
-3,34 -89
-1,56 -88
-0,47 -87
0 -86
-0,10 -85
-0,78 -84
-2,11 -83
-4,20 -82
-7,36 -81
-12,31 -80
-22,03 -79
-25,17 -78
现在,我确定 0 应该介于 0 和 -0,10 或 0 和 -0,47 之间。线性插值会给我太多错误,所以我想我会使用三次样条。
我需要做的是计算我的 Y REALLY = 0 的 X 参数。
太糟糕了,我无法使用我在 Internet 上找到的内容,因为我尝试的每个函数都从指定的 X 计算 Y(在代码示例下方)。任何人都可以帮忙吗?
Function SpLine(PeriodCol As Range, RateCol As Range, x As Range)
Dim Period_Count As Integer
Dim Rate_Count As Integer
Dim c As Integer
Dim n As Integer
Dim i, k As Integer
Dim p, qn, sig, un As Single
Dim klo, khi As Integer
Dim h, b, a As Single
' shows the calculation of a cubic spline interpolated value given known values for fixed periods
Period_Count = PeriodCol.Rows.Count
Rate_Count = RateCol.Rows.Count
If Period_Count <> Rate_Count Then
SpLine = "Error: Range count dos not match"
GoTo endnow
End If
ReDim xin(Period_Count) As Single
ReDim yin(Period_Count) As Single
For c = 1 To Period_Count
xin(c) = PeriodCol(c)
yin(c) = RateCol(c)
Next c
ReDim u(Period_Count - 1) As Single
ReDim yt(Period_Count) As Single
n = Period_Count
yt(1) = 0
u(1) = 0
For i = 2 To n - 1
sig = (xin(i) - xin(i - 1)) / (xin(i + 1) - xin(i - 1))
p = sig * yt(i - 1) + 2
yt(i) = (sig - 1) / p
u(i) = (yin(i + 1) - yin(i)) / (xin(i + 1) - xin(i)) - (yin(i) - yin(i - 1)) / (xin(i) - xin(i - 1))
u(i) = (6 * u(i) / (xin(i + 1) - xin(i - 1)) - sig * u(i - 1)) / p
Next i
qn = 0
un = 0
yt(n) = (un - qn * u(n - 1)) / (qn * yt(n - 1) + 1)
For k = n - 1 To 1 Step -1
yt(k) = yt(k) * yt(k + 1) + u(k)
Next k
klo = 1
khi = n
Do
k = khi - klo
If xin(k) > x Then
khi = k
Else
klo = k
End If
k = khi - klo
Loop While k > 1
h = xin(khi) - xin(klo)
a = (xin(khi) - x) / h
b = (x - xin(klo)) / h
SpLine = a * yin(klo) + b * yin(khi) + ((a ^ 3 - a) * yt(klo) + (b ^ 3 - b) * yt(khi)) * (h ^ 2) / 6
endnow:
End Function