%Purpose: calculate the integation of function f(x)=x
%Author: Jie Zhang
%Date:   Nov. 05, 2013
%Comments: this is for the CDS130 class

%specify the integration interval and number of iterations
a=0;    % lower limit
b=4;  % upper limit
N=4;  %Number of iterations

dx=(b-a)/N  %the sub-interval

%specify the initial value
x(1)=a;   % a=0
F(1)=x(1)*dx;

%iteration to find the integration value
for i=[1:N-1]
  x(i+1)=x(i)+dx;
  f(i+1) = x(i+1);
  F(i+1)=F(i)+f(i+1)*dx;
end

%
sprintf('The integration value = %f',F(N))
    