Comparison of the Integral of 1/x  with Riemann sums

Ivan Cnop
Vrije universiteit Brussel
icnop@vub.ac.be

Avoid messages

Off[Plot::plnr]

Intervals with constantlength 1

We start with some useful list programming

Clear[x]

height = 5;

values =  Table[1/j, {j, 14}]

howMany = Length[values];
rightEnd = howMany;
leftEnd = 0;
delta  = (rightEnd - leftEnd)/howMany

xes = Table[x, {x, leftEnd + delta, rightEnd, delta}]

slots =  
        Map[((# - delta) < x < (#)) &, xes];

slots

l = Flatten[Transpose[{slots, values}]];

l /. Head[l] -> Which

Clear[f]; f[x_] := l /. Head[l] -> Which

Plot[f[x],{x, leftEnd, howMany delta}
,AxesOrigin -> {leftEnd, 0},PlotRange -> {0, 2}]

left- and right values of the function

f[x_] := 1/x

fLinks =  Map[f, xes - delta ];

l1 = Flatten[Transpose[{slots, fLinks}]];

Clear[fL]; fL[x_] := l1 /. Head[l] -> Which

Plot[{f[x], fL[x]},{x, leftEnd, howMany delta}
,AxesOrigin -> {leftEnd, 0}]

fRight =  Map[f, xes]

l2 = Flatten[Transpose[{slots, fRight}]];

Clear[fR]; fR[x_] := l2 /. Head[l] -> Which

Plot[{f[x], fR[x]},{x, leftEnd, howMany delta}
,AxesOrigin -> {leftEnd, 0}]

Plot[{fL[x], f[x], fR[x]},{x, leftEnd, howMany delta}
,AxesOrigin -> {leftEnd, 0}]

<< Graphics`FilledPlot`

FilledPlot[{fL[x], f[x], fR[x]},{x, leftEnd, howMany delta}
,AxesOrigin -> {leftEnd, 0}
	,PlotRange -> {0, 1}
	,\(Fills\  -> \ {{{1, 2}, Hue[0]}, 
\ {{2, \ 3}, 
                Hue[ .3]}}\)
	,Curves  ->  Front]

Epilogue

The fraction of red area over all the area of all rectangles tends to Euler's constant

N[EulerGamma, 50]