Interpolation and curve line

6 次查看(过去 30 天)
Eddy Ramirez
Eddy Ramirez 2020-10-20
回答: KSSV 2020-10-21
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');

回答(1 个)

KSSV
KSSV 2020-10-21
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')

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by