Interpolation and curve line

5 vues (au cours des 30 derniers jours)
Eddy Ramirez
Eddy Ramirez le 20 Oct 2020
Réponse apportée : KSSV le 21 Oct 2020
Greetings,
I have the following data for x and y and I would like to interpolate for the y values along the x from -5 to 5 and I also would like to generage an ellipse curve
W4_x=[-5 -4 -3 -2 -1 0 1 2 3 4 5];
W4_y=[0 .254 .508 .762 1.016 1.27 1.016 .762 .508 .254 0];
%%%% I have tried the following codings, but they do not work%%%
%%% CODING 1%%%
%%p=polyfit(W4_x, W4_y, 100);
%%v=polyval(p, W4_x);
%%%CODING 2%%%
%n=100;
%W4_intx=linspace(min(W4_x), max (W4_x), n);
%W4_inty=interp1(W4_x, W4_y, W4_intx, 'spline');

Réponses (1)

KSSV
KSSV le 21 Oct 2020
x=[-5 -4 -3 -2 -1 0 1 2 3 4 5];
y=[0 .254 .508 .762 1.016 1.27 1.016 .762 .508 .254 0];
% Interpolation
xi = linspace(min(x),max(x),100) ;
yi = interp1(x,y,xi) ;
% Fit a quadtratic curve
p = polyfit(xi,yi,2) ;
% plot
plot(x,y,'.r')
hold on
plot(xi,yi,'b')
plot(xi,polyval(p,xi),'k')

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!

Translated by