Interpolation and curve line

8 ビュー (過去 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 Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by