(* PROJECT 7 - \(NUMERICAL\ INTEGRATION\ 

            	TRAPEZOIDAL\) + SIMPSONS
MILAN RAMAIYA - 2001.12  .05 *)
(* TRAPEZOIDAL ALGORITHM *)
trap[a_, b_, 
            h_] := 
(s = 0; 
For[i = a, 
              i < b, i += h, 
              s += ((h/2)) (f[i] + 
                      f[i + h])]; 
Return[
              s];
);
  
simp[a_, 
        b_, h_] := 
(
s = 
          0; 
For[i = a, i < b, i += 2  h, 
          s += ((h/3)) (f[i] + 4  f[i + h] + 
                  f[i + 2  h])]; 
Return[
          s];
)

f[
            x_] = (E^((x^2))) Sin[2.  π x];
  
Print["OUTPUT"];
\(Print[\*""Trapezoidal, h=\!\(1\/10\):  "", 
        trap[0, 1, 
          1/10]];\)
\(Print[\*""Trapezoidal, h=(1/100): "", 
        trap[0, 1, 
          1/100]];\)
\(Print[\*""Simpsons,    h=\!\(1\/10\):  "", 
        simp[0, 1, 
          1/10]];\)
\(Print[\*""Simpsons,    h=(1/100): "", simp[0, 1, 1/100]];\)