gpt4 book ai didi

r - R中的基本二维三次样条拟合

转载 作者:太空宇宙 更新时间:2023-11-03 19:51:02 24 4
gpt4 key购买 nike

二维空间中简单的 Matlab 三次样条插值的 R 等效值是多少 here ,即

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 向量进行排序,并且深入研究相关问题并没有让我有任何进一步的进展。谢谢...

最佳答案

可能这是 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)

请注意,我不确定spline的算法是否与matlab完全相同。

enter image description here

关于r - R中的基本二维三次样条拟合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8611491/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com