Basic two-dimensional cubic spline fitting in R

What is the equivalent of R simple interpolation of the cubic spline Matlab 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 

I tried the variations in R, but they seem to require the ordering of the vector x, and digging into related issues did not lead me to further. Thanks...

+4
source share
1 answer

Perhaps this is version 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) 

Note that I'm not sure if spline algorithms are completely identical with matlab.

enter image description here

+10
source

Source: https://habr.com/ru/post/1387666/


All Articles