%Lab 2
%Written by Jeannette Spuhler, 2011-09-07
%Modified 2011-11-03

%Simpsons regel
%NUM 6.2a
clear all;clc;
format long;
n=10;
h=3/n;
x=0;
y=x+h; 
simsum = 0;

for i =1:n
    simsum = simsum+((y-x)/6)*(f62a(x)+4*f62a((x+y)/2)+f62a(y));
    x= y;
    y=x+h;
end


%Bisection of the step size
times = 5;
steph = [];
Savesimsum = [];
for steghalvering = 1:times
     n=2*n;
     h=h/2;
     steph = [steph; h];
     x=0;
     simsum = 0;
     y=x+h;
     for i =1:n
        simsum = simsum+((y-x)/6)*(f62a(x)+4*f62a((x+y)/2)+f62a(y));
        x= y;
        y=x+h;
     end
     Savesimsum = [Savesimsum; simsum];
end

disp('Integral value calculated with Simpson rule using bisection of step size: ');
disp('       h                Integral Value')
disp( [steph Savesimsum ]);
format short;