小编Mar*_*ius的帖子

R中的三次样条插值

我正在尝试在R中实现三次样条函数.我已经使用了R库中可用的样条曲线,smooth.spline和smooth.Pspline函数,但我对结果并不满意所以我想说服自己通过"自制"样条函数得出结果的一致性.我已经计算了三次多项式的系数,但我不知道如何绘制结果......它们似乎是随机点.您可以在下面找到源代码.任何帮助,将不胜感激.

x = c(35,36,39,42,45,48)
y = c(2.87671519825595, 4.04868309245341,   3.95202175000174,   
  3.87683188946186, 4.07739945984612,   2.16064840967985)


n = length(x)

#determine width of intervals
h=0
for (i in 1:(n-1)){
   h[i] = (x[i+1] - x[i])
}

A = 0
B = 0
C = 0
D = 0
#determine the matrix influence coefficients for the natural spline
for (i in 2:(n-1)){
  j = i-1
  D[j] = 2*(h[i-1] + h[i])
  A[j] = h[i]
  B[j] = h[i-1] 

}

#determine the constant matrix C
for (i in 2:(n-1)){
  j …
Run Code Online (Sandbox Code Playgroud)

plot r spline cubic

-2
推荐指数
1
解决办法
4529
查看次数

标签 统计

cubic ×1

plot ×1

r ×1

spline ×1