# # 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: # gnuplot plot.plotin # to use interactively: # omit or comment out the following two lines, then from gnuplot: # load "plot.plotin" set terminal png set output "plot.png" # 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 spacing 6 set size square 1,1 set border 3 plot \ 4.0 / (1.0 + x*x) \ title "function 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