function integral1d=integrate_in_1d(f, a, b)
% integration with simple rectangles/box method
% int_a^b f(x) dx

N=100; % number of points in the sum 
x=linspace(a,b,N);

%% this loop can be done in one shot, see below
integral1d=0;
for xi=x
    integral1d = integral1d + f(xi);
end

%% Alternative which utilizes the Matlab matrix calculations
% if function f can work with vector argument then we can do
% integral1d = sum ( f(x) ); % this replaces above loop and often is faster

%% in rectangles method we need to subtract last element
integral1d = integral1d-f(x(end));

%% now we calculate the integral
integral1d = integral1d*(b-a)/(N-1);


