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

1 visualizzazione (ultimi 30 giorni)
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);

Risposta accettata

Hiro Yoshino
Hiro Yoshino il 29 Set 2022
I would use Symbolic Math Toolbox to solve the problem analytically:
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) % create pp object
s = struct with fields:
form: 'pp' breaks: [0.7000 1 1.5000 1.8000 2.1000 3.6000 4.4000 5.7000 8 12 21 29 74] coefs: [12×4 double] pieces: 12 order: 4 dim: 1
xq = min(x):max(x);
s1 = spline(x,y,xq); % just for plot
plot(xq,s1)
hold on;
yline(600); % serch solution roughly
ax = gca;
ax.XTick = s.breaks;
xline(s.breaks,':');
hold off;
xlim([0.82 7.35])
ylim([478 718])
The solution seems to lie in the 5th section.
The coefficients of the function corresponding to the 5th sections are
s.breaks
ans = 1×13
0.7000 1.0000 1.5000 1.8000 2.1000 3.6000 4.4000 5.7000 8.0000 12.0000 21.0000 29.0000 74.0000
s.coefs(5,:)
ans = 1×4
-64.8873 190.9875 -200.4848 620.0000
Extract coefficients
x1 = s.breaks(5)
x1 = 2.1000
x2 = s.breaks(6)
x2 = 3.6000
a = s.coefs(5,1)
a = -64.8873
b = s.coefs(5,2)
b = 190.9875
c = s.coefs(5,3)
c = -200.4848
d = s.coefs(5,4)
d = 620
Use Symbolic math to analytically solve the problem
syms x
f(x) = a*(x-x1)^3+b*(x-x1)^2 + c*(x-x1) + d
f(x) = 
sol = vpasolve(f==600,x,x1) % solutions at y = 600
sol = 
x = 2.211 or something.

Più risposte (0)

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by