interpolation methods to calculate the value of y

29 Ansichten (letzte 30 Tage)
salim tasan
salim tasan am 12 Apr. 2019
Kommentiert: darova am 12 Apr. 2019
use linear, spline and cubic interpolation methods to calculate the value of y. Plot data points and graphs of three interpolation methods.Estimate the value of y for x = 7.5 using three interpolation methods. displayyour results along with text which technique was used to produce each value.
x = [10 20 30 40 50];
y = [0.9530 0.7221 0.4510 0.6132 0.5518];
this is what I got, but I do not know if it any correct
x = [10 20 30 40 50];
y = [0.9530 0.7221 0.4510 0.6132 0.5518];
plot(x,y,'ob')
xi=1:0.1:10;
method=char('linear','cubic','spline');
col={'--r',':g','-k'};
for k=1:3
yi{k}=interp1(x,y,xi,method(k,:));
hold on;
plot(xi,yi{k},col{k})
end
legend('linear','cubic','spline', 'Location', 'best');
title(sprintf('x = 7.5 y is %.2f ',polyval(fit,7.5)))
y1=yi{1};
y2=yi{2};
y3=yi{3};
  1 Kommentar
darova
darova am 12 Apr. 2019
You forgot data
legend('data','linear','cubic','spline', 'Location', 'best');
To obtain y at x = 7.5:
xp = 7.5;
yp = interp1(x,y,xp,method);
plot(xp,yp,'or')
text(xp,yp,method)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KSSV
KSSV am 12 Apr. 2019
x = [10 20 30 40 50];
y = [0.9530 0.7221 0.4510 0.6132 0.5518];
plot(x,y,'ob')
xi=min(x):0.1:max(x);
method=char('linear','cubic','spline');
col={'--r',':g','-k'};
yi = zeros(3,length(xi)) ;
for k=1:3
yi(k,:)=interp1(x,y,xi,method(k,:));
end
plot(xi,yi) ;
legend('linear','cubic','spline', 'Location', 'best');
% title(sprintf('x = 7.5 y is %.2f ',polyval(fit,7.5)))

Weitere Antworten (0)

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by