Given the data points (xs,ys), we plot the curve at the data points in x using Matlab code below:
Required Matlab code with explanatory comments is below:
ys=[0 0.9 0.6 1 0 0.1 -0.3 -0.7 -0.9 -0.2]; %y sample
points
xs=0:length(ys)-1; %x sample points
x=0:0.1:length(ys)-1; %x data points
p3=polyfit(xs,ys,3); %fit third degree polynomial to (xs,ys)
p7=polyfit(xs,ys,7); %fit seventh degree polynomial to
(xs,ys)
plot(xs,ys,'ro'); %plot sample points as red dots
hold on
plot(x,polyval(p3,x),'b--'); %plot as blue dashed lines
plot(x,polyval(p4,x),'g--'); %plot as green double dashed
lines
legend('Sample points','3rd degree polynomial', '7th degree
polynomial', 'Location', 'NorthEast') %add a legend
Resulting plot is below:
Please do rate this answer positively if you found it helpful. Thanks and have a good day!
matlap 3, Programmi ng Polynomial interpolation has been known sample points are plotted ys different ways...