# # plot function whose integral is pi, and approximation as computed by # simple numerical integration. intended to be used with LaTeX, so # function can be typeset using its math mode. # # data for approximation is generated inline using what in essence is # a miniature shell script (using "bc" for the calculations). no # claims are made for the superiority or readability of this method, # but it was fun to write! # # to run in batch to produce EPS: # plot2eps numerical-integration.plotin # to use interactively, from gnuplot: # load "numerical-integration.plotin" # neither way produces output that is ideal; further tweaking is # needed. # change "n=" in the plot command below to vary the number of rectangles # used in the approximation. set xrange [0:1] set yrange [0:4] set xtics axis nomirror 0.2 set ytics axis nomirror 1 set key outside Right set size square 1,1 set border 3 plot \ 4.0 / (1.0 + x*x) \ title "function \$\\frac{4}{(1 + x^2)}\$" with line lw 2, \ '< n=10; seq 0 $(($n-1)) | while read i; do \ echo "scale=4; x=($i + 0.5)/$n; y=4.0/(1.0+x*x); \ print x, \" \", y, \"\n\" " | bc; \ done' \ title "approximation" with boxes lw 2