/** Plot.irx **/ /** usage: PLOT x_init x_final func [npts] **/ /** example: PLOT 0 10 y=sin(x) 30 **/ /** **/ /** Plot function 'func' at 'npts' points over **/ /** the range [x_init...x_final]. Call the **/ /** IntroCAD-ARexx program AXES to draw axes **/ /** and a box around the plot **/ OPTIONS FAILAT 20 SIGNAL ON FAILURE ARG x_init x_final func npts . ADDRESS "ICAD" IF x_init = "?" THEN DO '*message usage: Plot x_init x_final function [npts]' '*message example: Plot 0 10 y=sin(x) 30' RETURN END /* abort anything already going on */ '\e' /* This may take a second; Let user know we're on the job */ '*message Working...' x_init = evaluate(x_init, 0) x_final = evaluate(x_final, 1) npts = evaluate(npts, 30) xmin = MIN(x_init, x_final) xmax = MAX(x_init, x_final) xstep = (xmax-xmin)/npts ymin=1000000; ymax=-1000000 NUMERIC DIGITS 8 DO i=1 TO npts x = xmin + (i-1) * xstep INTERPRET func ymin = MIN(ymin,y) ymax = MAX(ymax,y) xarray.i = x yarray.i = y END xs = 1 ys = (2/3)*(xmax-xmin)/(ymax-ymin) /* get IntroCAD to do our scaling for us */ '*transform push' '*transform default' '*scale' xs ys '/Draw/Line' DO i=1 TO npts xarray.i yarray.i'!' END '!' /* end the line plot */ /* DRAW AXES */ NUMERIC DIGITS 2 yslop = (ymax-ymin)/10 ymin = +ymin ymax = +ymax xslop = (xmax-xmin)/10 tic_step = MAX(xslop, yslop) num_step = tic_step /* use Axes.irx to draw the box, tics, and axis labels */ Axes xmin-xslop xmax+xslop ymin-yslop ymax+yslop tic_step num_step /* CLEAN UP */ '*transform pop' RETURN failure: EXIT 20 evaluate: ARG string, default IF DATATYPE(string, "NUM") THEN RETURN(string) IF STRING = "" THEN RETURN(default) string = 'string='string INTERPRET string RETURN string