# # 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 and generate complete EPS file (using script plot2eps) # # plot2eps plot-latex.plotin # or uncomment the next two lines and process output file with LaTeX # set terminal epslatex color standalone clip # set output "plot-latex.tex" # 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 \$\\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