h=1;
Nmax = 50;

hv = zeros(Nmax,1);
Error1 = zeros(Nmax,1);
Error2 = zeros(Nmax,1);
Error3 = zeros(Nmax,1);

x = 0.5;
exact = cos(x);
for j=1:Nmax
   h = h/2;
   Error1(j) = abs((sin(x+h)-sin(x))/h-exact);
   Error2(j) = abs((sin(x+h)-sin(x-h))/(2*h)-exact);
   Error3(j) = abs((-sin(x+2*h)+8*sin(x+h)-8*sin(x-h)+sin(x-2*h))/(12*h)-exact);
   hv(j) = h;
end

figure(1)
loglog(hv,Error1,'b-','linewidth',2)
hold on
loglog(hv,Error2,'r-','linewidth',2)
hold on
loglog(hv,Error3,'k-','linewidth',2)
hold off
xlabel('h')
ylabel('Error')
legend('Skjema 1','Skjema 2','Skjema 3')

figure(2)
plot(hv,Error1,'b-')
hold on
plot(hv,Error2,'r-')
hold on
plot(hv,Error3,'k-')
hold off