cubic spline interpolation based on intermediate iterative points.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
x(1)= 1;
y(1)= 5.8;
x(2)= 2.5;
y(2)=12.8125;
x(3)=3;
y(3)=18.2;
x(4)= 4.5;
y(4)= 48.7625;
x(5)= 5.2;
y(5)= 72.496;
So we'e trying to find intermediate points between these points. And will display matrix where we want to display these points plus the new ones we found.
%getting intermediate points
for i=1:n-1
b(i) = (x(i)+x(i+1))./2;
A = x;
C = b(:,[1;1]*(1:size(b,2)));
C(:,1:2:end) = A;
end
C
%code to interpolate the intermediate values
for i=2:n-1
c1= d2(i-1)./(6.*(C(i+1)- C(i-1)));
c2= d2(i+1)./(6.*(C(i+1)- C(i-1)));
c3= (y(i-1)./(C(i+1)-C(i-1)))-((d2(i-1)).*(C(i+1)-(C(i-1)))./6);
c4= ((y(i+1)./(C(i+1)-C(i-1))-(d2(i+1).*(C(i+1)-C(i-1))./6)));
t1= c1.*((C(i+1)-C(i)).^3);
t2= c2.*((C(i)-C(i-1)).^3);
t3= c3.*(C(i+1)-C(i));
t4= c4.*(C(i)-C(i-1));
y(i-1)=t1+t2+t3+t4;
end
C(4)
y(4)
thats what we used but we keep getting the wrong answers, as if we only have the orignal values only
C =
1.0000 1.7500 2.5000 2.7500 3.0000 3.7500 4.5000 4.8500 5.2000 0
ans =
2.7500
ans =
48.7625
0 commentaires
Réponses (1)
Hrishikesh Borate
le 5 Fév 2021
Hi,
It’s my understanding that you are trying to perform cubic spline interpolation between points x and y, using the interpolated points.
Following is the code for the same :-
x(1) = 1;
y(1) = 5.8;
x(2) = 2.5;
y(2) = 12.8125;
x(3) = 3;
y(3) = 18.2;
x(4) = 4.5;
y(4) = 48.7625;
x(5) = 5.2;
y(5) = 72.496;
n = 5;
for i = 1:n-1
interpolatedPoints(2*i-1) = x(i);
interpolatedPoints(2*i) = (x(i)+x(i+1))./2;
end
interpolatedPoints(2*i+1) = x(n);
yy = spline(x,y,interpolatedPoints);
plot(x,y,'o',interpolatedPoints,yy)
0 commentaires
Voir également
Catégories
En savoir plus sur Splines 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!