This code implements the Trapezoid Rule method of numerically approximating the integral of a function.  I provide this file to Math 216 students, who can change the values of f, a, b, n, ymin and ymax below, and then re-execute the code to produce a picture of a region whose area is being calculated, trapezoids which approximate the region, and the numerical approximation to the indicated area.  An example of the output is below.

(* this line defines the function f *)
f[x_] = x + (1/8)Sin[20x];

(* a and b are the left and right endpoints of the region *)
a = 1;
b = 2;

(* n is the number of trapezoids *)
n = 4;

(* ymin and ymax are the smallest and largest values of y you see in the picture *)
ymin =0;
ymax = 3;

(* Don't mess with anything below this *)

points = Range[a,b,(b-a)/n];
data = Transpose[{points, f[points]}];
Show[ListLinePlot[data, InterpolationOrder -> 1, PlotStyle -> {Thick, Red}, PlotRange -> {{a-1, b+1},{ymin, ymax}}, Filling -> 0, FillingStyle -> {Opacity[.15]}],
Plot[f[x], {x, a-1, b+1}, PlotStyle -> {Thick, Blue}, PlotRange -> {ymin, ymax}]]

(2 Sum[f[points[[i]]], {i, 2, n}] + f[points[[1]]] + f[points[[n+1]]])(b-a)/(2n)

N[(2 Sum[f[points[[i]]], {i, 2, n}] + f[points[[1]]] + f[points[[n+1]]])(b-a)/(2n)]