本文介绍了R中的基本二维三次样条拟合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在2D空间中显示的简单Matlab三次样条插值的R等效项是此处,即
What is the R equivalent of the simple Matlab cubic spline interpolation in 2D space shown here, i.e.
n = 7;
x = rand(n,1);
y = rand(n,1);
plot(x,y,'.')
axis([0 1 0 1])
t = 1:n;
ts = 1:1/10:n;
xs = spline(t,x,ts);
ys = spline(t,y,ts);
hold on
plot(xs,ys,'r');
hold off
我已经尝试了R的变体,但它们似乎需要对x向量进行排序,而深入研究相关问题并没有让我更进一步.谢谢...
I've tried variations in R but they seem to require ordering of the x vector, and digging through the related questions didn't get me any further. Thanks...
推荐答案
可能是R版本:
n <- 7
x <- runif(n)
y <- runif(n)
t <- 1:n
ts <- seq(1, n, by = 1/10)
xs <- splinefun(t, x)(ts)
ys <- splinefun(t, y)(ts)
plot(x, y, xlim = c(0, 1), ylim = c(0, 1))
lines(xs, ys)
请注意,我不确定样条线的算法是否与matlab完全相同.
Note that I'm not sure if the algorithms of spline is completely identical with matlab.
这篇关于R中的基本二维三次样条拟合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!