Interpolation and curve line
10 views (last 30 days)
Show older comments
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');
0 Comments
Answers (1)
KSSV
on 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')
0 Comments
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!