%interpolace dat
clear; clc; 
x = 0:0.8:10; 
y = x.*exp(-x); 
%y = sin(x); 
xi = 0:.2:10; 
yi = interp1(x,y,xi); 

figure(1)
plot(x,y,'o',xi,yi)
hold on
yi2 = interp1(x,y,xi,'spline');
plot(xi,yi2,'g')
hold on
yi3 = interp1(x,y,xi,'pchip','extrap');
plot(xi,yi3,'r')
hold off

X = 0:0.1:10;
p = polyfit(x,y,length(x)-1);
Z = polyval(p,X);

figure(2)
plot(x,y,'o')
hold on
plot(X,Z,'g')
hold off

z=y+0.1*(2*rand(size(x))-1);


%polynomialni aproximace dat
p1 = polyfit(x,z,5);
Z1 = polyval(p1,X);

p2 = polyfit(x,z,10);
Z2 = polyval(p,X);




figure(3)
plot(x,z,'o')
hold on
plot(X,Z1,'r')
hold on
plot(X,Z2,'g')
hold off




