% Harjutustund 9, ylesanne 5
x=[-1,0.1,0.5,3,4,6.3,7,9,14,21];
y=[-2,0.4,0.7,2,4,3.6,3.8,6,-1,12];
disp([x;y])
plot(x,y,'o')
% 1) esimese astme polynoomiga 
p1=polyfit(x,y,1)
% p(x)=0.4172*x+0.2839
yp1=polyval(p1,x);
disp([x;y;yp1])
hold on
plot(x,yp1)
% 2) 2. astme polynoom
p2=polyfit(x,y,2)
yp2=polyval(p2,x);
hold on
plot(x,yp2)
% 3) 3. astme polynoom
p3=polyfit(x,y,3)
xvork=[-1:0.1:21];
yp3=polyval(p3,xvork);
hold on
plot(xvork,yp3)

% 4) 6. astme polynoom
p6=polyfit(x,y,6)
yp6=polyval(p6,xvork);
hold on
plot(xvork,yp6)

% 5) polynoomi v22rtus kohal 3.5
polyval(p2,3.5)
polyval(p6,3.5)