interpolationsplinescilabcubic-spline

Cubic spline or polynomial interpolation of non strictly increasing x in Scilab


I have a set of xy points:

x = [1 2 3 3 2]
y = [1 1 2 3 2]

plot of the points

I would like to do an interpolation of those point. My issue is, interp1() or splin() require a strictly ecreasing x.

How can I get an interpolation like this:

x = [1 2 3 4 5]
y = [1 1 2 3 2]
xx = linspace(1, 5, 100);
yy2 = interp1(x, y, xx, 'spline');
plot(xx',yy2)
scatter(x, y)

interp1 interpolation plot

But with a non increasing x ?

I do not only need the plot, but also get the interpolation value for a given x and y.


Solution

  • This is a parametric curve, you have to consider a third vector t (the values of the parameter) and compute two splines. You can change the spline type by changing the third parameter (see the splin help page):

    x = [1 2 3 3 2];
    y = [1 1 2 3 2];
    t = 1:5;
    dx = splin(t,x,"natural");
    dy = splin(t,x,"natural");
    tt=linspace(t(1),t($),1000);
    plot(interp(tt,t,x,dx),interp(tt,t,y,dy),x,y,'o')
    

    enter image description here