How to interpolate a set of data with the cubic method?

2 vues (au cours des 30 derniers jours)
Pipe
Pipe le 29 Sep 2022
Commenté : John D'Errico le 29 Sep 2022
I tried looking it up, and it comes out that i should use the spline command, but when i use it nothing comes out. I need to plot the data and the interpolant. I also need to find x for when y= 600
x = [74 29 21 12 8 5.7 4.4 3.6 2.1 1.8 1.5 1.0 0.7];
y = [80 131 189 270 320 407 450 530 620 686 740 900 1095];
s = spline(x, y, 600);
  3 commentaires
Pipe
Pipe le 29 Sep 2022
You are right, i meant y=600
John D'Errico
John D'Errico le 29 Sep 2022
Note that this is rather noisy looking data, and it has large changes in slope. That makes a cubic spline a terribly poor choice to model that curve, even if it appears it survived the process and produced a monotonic curve. Using a higher order interpolant to model noise is often a bad idea.
Instead, use pchip, a tool designed not to introduce spurious extrema and non-monotonic behavior into a problem. The curve will still come out looking smooth.

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 29 Sep 2022
x = [74 29 21 12 8 5.7 4.4 3.6 2.1 1.8 1.5 1.0 0.7];
y = [80 131 189 270 320 407 450 530 620 686 740 900 1095];
yi = linspace(min(y),max(y)) ;
xi = interp1(y,x,yi,'spline') ;
plot(x,y,'*r',xi,yi,'b')
x_600 = interp1(y,x,600,'spline') ;
  1 commentaire
John D'Errico
John D'Errico le 29 Sep 2022
Note that this is rather noisy looking data, and it has large changes in slope. That makes a cubic spline a terribly poor choice to model that curve, even if it appears it survived the process and produced a monotonic curve. Using a higher order interpolant to model noise is often a bad idea.
Instead, use pchip, a tool designed not to introduce spurious extrema and non-monotonic behavior into a problem. The curve will still come out looking smooth.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by