% 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')
% a) esimese astme polynoomiga
p1=polyfit(x,y,1)
% p(x)=0.4172x+0.2839
yp1=polyval(p1,x);
hold on
plot(x,yp1)

% b) teise astme polynoomiga
p2=polyfit(x,y,2)
% p(x)=0.0078x^2+0.2684x+0.5846
yp2=polyval(p2,x);
hold on
plot(x,yp2)

% c) kolmanda astme polynoomiga
p3=polyfit(x,y,3)
xvork=[-1:0.1:21];
yp3=polyval(p3,xvork);
hold on
plot(xvork,yp3)

% d) kuuenda astme polynoomiga
p6=polyfit(x,y,6)
yp6=polyval(p6,xvork);
hold on
plot(xvork,yp6)

% e) polynoomi v22rtused
polyval(p2,3.5)
polyval(p6,3.5)
