%Hermiteinterpolation
x=[-1 -0.4 0 0.4 1]';
y=[0.06 0.28 1 0.28 0.06]';
k=[0.11 1.01 0 -1.01 -0.11]';
plot(x,y,'o'),hold on
h=diff(x);dy=diff(y);
g=h.*k(1:4)-dy;
c=2*dy-h.*(k(1:4)+k(2:5));
t=0:0.1:1;
for i=1:4
    xt=x(i)+t*h(i);
    yt=y(i)+t*dy(i)+t.*(1-t)*g(i)+t.^2.*(1-t)*c(i);
    plot(xt,yt)
end
title('Hermiteinterpolation (blå)och fuskspline (röd)')
%Fusksplineinterpolation
k(1)=(y(2)-y(1))/(x(2)-x(1));
k(2:4)=(y(3:5)-y(1:3))./(x(3:5)-x(1:3));
k(5)=(y(5)-y(4))/(x(5)-x(4));
g=h.*k(1:4)-dy;
c=2*dy-h.*(k(1:4)+k(2:5));
t=0:0.1:1;
for i=1:4
    xt=x(i)+t*h(i);
    yt=y(i)+t*dy(i)+t.*(1-t)*g(i)+t.^2.*(1-t)*c(i);
    plot(xt,yt,'r')
end
hold off

