Mathematica Code

<<Graphics`FilledPlot`
RiemannSum[f_,a_,b_,n_,proportion_:(1/2)]:=
   Module[{h=(b-a)/n,p=1-proportion,s},s=Sum[f[a+(i-p)h],{i,1,n}];h*s]
LeftEndpointRule[f_,{x_,a_,b_,n_}]:=RiemannSum[f,{x,a,b,n},0]

RightEndpointRule[f_,{x_,a_,b_,n_}]:=RiemannSum[f,{x,a,b,n},1]

TrapezoidRule[f_,{x_,a_,b_,n_}]:=
   (RiemannSum[f,{x,a,b,n},0]+RiemannSum[f,{x,a,b,n},1])/2

MidpointRule[f_,{x_,a_,b_,n_}]:=RiemannSum[f,{x,a,b,n},1/2]
SimpsonRule[f_,{x_,a_,b_,n_}]:=
   (TrapezoidRule[f,{x,a,b,n}]+2*MidpointRule[f,{x,a,b,n}])/3


Converted by Mathematica      February 18, 2001