How to interpolate a set of data with the cubic method?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Pipe
le 29 Sep 2022
Réponse apportée : Hiro Yoshino
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);
0 commentaires
Réponse acceptée
Hiro Yoshino
le 29 Sep 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
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
s.coefs(5,:)
Extract coefficients
x1 = s.breaks(5)
x2 = s.breaks(6)
a = s.coefs(5,1)
b = s.coefs(5,2)
c = s.coefs(5,3)
d = s.coefs(5,4)
Use Symbolic math to analytically solve the problem
syms x
f(x) = a*(x-x1)^3+b*(x-x1)^2 + c*(x-x1) + d
sol = vpasolve(f==600,x,x1) % solutions at y = 600
x = 2.211 or something.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!