program expgraph(input,output); (* exptraph: make a graph of the exponential function Dr. Thomas D. Schneider National Cancer Institute Laboratory of Experimental and Computational Biology Frederick, Maryland 21702-1201 toms@ncifcrf.gov permanent email: toms@alum.mit.edu http://www.lecb.ncifcrf.gov/~toms/ *) label 1; (* end of program *) const (* begin module version *) version = 1.07; (* of expgraph.p 2000 June 25 2000 June 25: 1.07: upgrade documentation 1995 July 28: 1.04: last major changes origin 1995 July 27 from version 1.06 of hgraph 1988 oct 4 *) (* end module version *) (* begin module describe.expgraph *) (* name expgraph: make a graph of the exponential function synopsis expgraph(input: intty, output: out) files input: two numbers, one per line: number of divisions to plot per integer; maximum of x (minimum is zero). output: x versus 2^x in three columns: first column is 'n' for numerical data or 'p' for places that should be marked with a circle (ie, nice integer values) second column is x running from 0 to the maximum of x third column is 2^x description The powers of 2 exponential function. The same data can be plotted to give the logarithmic function. examples For an exponential graph, the xyplop file to use is: 4 2 zerox zeroy graph coordinate center x 0 5 zx min max (character, real, real) if zx='x' then set xaxis y 0 32 zy min max (character, real, real) if zy='y' then set yaxis 5 32 1 1 xinterval yinterval xsubintervals ysubintervals: axis intervals 4 4 xwidth ywidth width of numbers in characters 0 0 xdecimal ydecimal number of decimal places 15 17 xsize ysize size of axes in cm x y = 2) show gsave 24 8 translate 0 0 moveto (x) show grestore ( a zc 'c' crosshairs, axXyYnN n 2 zxl base if zxl='l' then make x axis log to the given base n 2 zyl base if zyl='l' then make y axis log to the given base ********************************************************************* 2 3 xcolumn ycolumn columns of xyin that determine plot location 1 symbol column the xyin column to read symbols from 0 0 xscolumn yscolumn columns of xyin that determine the symbol size 0 0 0 hue saturation brightness columns for color manipulation ********************************************************************* symbol-to-plot c(circle)bd(dotted box)x+Ifgpr(rectangle) n symbol-flag character in xyin that indicates that this symbol 0.05 symbol sizex side in inches on the x axis of the symbol. 0.05 symbol sizey as for the x axis, get size from yscolumn cl 0.05 no connection (example for connection is c- 0.05 for dashed 0.05 inch) n 0.05 linetype size linetype l.-in and size of dashes or dots ********************************************************************* c symbol-to-plot c(circle)bd(dotted box)x+Ifgpr(rectangle) p symbol-flag character in xyin that indicates that this symbol 0.05 symbol sizex side in inches on the x axis of the symbol. 0.05 symbol sizey as for the x axis, get size from yscolumn nu 0.05 no connection (example for connection is c- 0.05 for dashed 0.05 inch) n 0.05 linetype size linetype l.-in and size of dashes or dots ********************************************************************* . **** version 8.50 of xyplop: uses cm for distances For an logarithmic graph, the xyplop file to use is: 4 2 zerox zeroy graph coordinate center x 0 32 zx min max (character, real, real) if zx='x' then set xaxis y 0 5 zy min max (character, real, real) if zy='y' then set yaxis 32 5 1 1 xinterval yinterval number of intervals on axes to plot 4 4 xwidth ywidth width of numbers in characters 0 0 xdecimal ydecimal number of decimal places 17 15 xsize ysize size of axes in inches x y = log ) show gsave 34.5 -7 translate 0 0 moveto (2) show grestore ( x a zc 'c' crosshairs, axXyYnN 2^x n 2 zxl base if zxl='l' then make x axis log to the given base n 2 zyl base if zyl='l' then make y axis log to the given base ********************************************************************* 3 2 xcolumn ycolumn columns of xyin that determine plot location 1 symbol column the xyin column to read symbols from 0 0 xscolumn yscolumn columns of xyin that determine the symbol size 0 0 0 hue saturation brightness columns for color manipulation ********************************************************************* symbol-to-plot c(circle)bd(dotted box)x+Ifgpr(rectangle) n symbol-flag character in xyin that indicates that this symbol 0.05 symbol sizex side in inches on the x axis of the symbol. 0.05 symbol sizey as for the x axis, get size from yscolumn cl 0.05 no connection (example for connection is c- 0.05 for dashed 0.05 inch) n 0.05 linetype size linetype l.-in and size of dashes or dots ********************************************************************* c symbol-to-plot c(circle)bd(dotted box)x+Ifgpr(rectangle) p symbol-flag character in xyin that indicates that this symbol 0.05 symbol sizex side in inches on the x axis of the symbol. 0.05 symbol sizey as for the x axis, get size from yscolumn nu 0.05 no connection (example for connection is c- 0.05 for dashed 0.05 inch) n 0.05 linetype size linetype l.-in and size of dashes or dots ********************************************************************* . ********************************************************************* documentation See direct pointers below. see also {A figure created by these two graphs (with 100 divisions) are used in the Information Theory Primer,} http://www.lecb.ncifcrf.gov/~toms/paper/primer {Example input files:} {exponential and log input file:} expgraph.expin {exponential xyplop:} expgraph.exponential.xyplop {logarithmic xyplop:} expgraph.logarithmic.xyplop {The program used to plot the graph is } xyplo.p author Thomas Dana Schneider bugs none known *) (* end module describe.expgraph *) var d: integer; (* index to the plot *) divisions: integer; (* number of divisions to plot *) ln2: real; (* precalculate ln(2) *) x: real; (* x axis value *) y: real; (* y axis value *) rangeofx: integer; (* range of x *) tolerance: real; (* how close to an integer we should be to put out the marker symbol *) begin writeln(output,'* expgraph ',version:4:2); ln2 := ln(2); writeln(output,'* number of divisions: '); readln(input,divisions); writeln(output,'* ',divisions:1); if divisions < 2 then divisions := 2; tolerance := 0.5/divisions; writeln(output,'* range of x: '); readln(input,rangeofx); writeln(output,'* ',rangeofx:1); for d := 0 to divisions * rangeofx do begin x := d / divisions; (* 2^x = exp(ln(2^x)) = exp(x*ln(2)) *) y := exp(x * ln2); writeln(output,'n ',x:10:8,' ',y:10:8); (* we add 1 to x since the trunc function is towards zero and won't work at zero otherwise: *) if trunc(1+x-tolerance) < trunc(1+x) then writeln(output,'p ',x:10:8,' ',y:10:8) end; 1:end.