% Harjutustund 8, ylesanne 4
% andmed 
x=[1,2,4,6];
y=[2,-2,-2,2];
plot(x,y,'o')
yline(0)
xline(0)
grid on
axis([-2,8,-4,4])
% Lagrange'i interpolatsioonipolünoom 
% Phi(x)=c3*x^3+c2*x^2+c1*x+c0
syms xx;
% Polünoomid L_3,i
l30=((xx-2)*(xx-4)*(xx-6))/((1-2)*(1-4)*(1-6));
l31=((xx-1)*(xx-4)*(xx-6))/((2-1)*(2-4)*(2-6));
l32=((xx-1)*(xx-2)*(xx-6))/((4-1)*(4-2)*(4-6));
l33=((xx-1)*(xx-2)*(xx-4))/((6-1)*(6-2)*(6-4));
Lagrpol=l30*2+l31*(-2)+l32*(-2)+l33*2
simplify(Lagrpol)
