% Integrals - area under the curve
  clear
%------- Problem-----------------
  x = sym('x');
  p = sin(2*x);
  A = 0.2;
  a = 0.1;
  b = pi/2;
  n = 20;
%--------------------------------
  clf
  
  dx = ( b - a ) / n;
  w = 0;
  for i = 1 : n
    xi(i) = a + (2*(i-1)+1)*dx/2;
    fi(i) = A * subs ( p, xi(i) ); % force at xi
    dwi(i) = fi(i) * dx;    % elemental work
    wi(i) = w + dwi(i);  % adding elemental work
    w = wi(i);
  end
  
  plot ( xi, fi, 'k-', 'LineWidth', 3 );
  
  for i = 1 : n
    h = rectangle ( 'Position', [xi(i)-dx/2, 0, dx, fi(i) ] );
    set ( h, 'FaceColor', 'g' );
    set ( h, 'LineWidth', 2 );
    pause ( 0.4 );
  end
  hold on
  plot ( xi, fi, 'k-', 'LineWidth', 3 );  
  
  xlabel ( 'x' );
  ylabel ( 'F(x)' );
  title ( 'Approximating an integral' ) 