[comp.sys.handhelds] Plotting data point on HP48

rouben@math13.math.umbc.edu (02/02/91)

How does one plot the graph of a function given in a tabular form?

Specifically, I have a program that generates a sequence of (x,y)
pairs and stores them in the stack.  The pairs represent points
on the graph of the solution of a differential equation.
Does anyone have a utility program for plotting a graph passing
through these points?  A simple linear interpolation between the points
will suffice.

The closest thing I could find in HP48's built-ins was the scatter-plot
function of the STAT utility in which a set of data points can be 
fitted with a linear, power, logarithmic or exponetial functions.  
Their applicability to my purposes is limited since these curve-fitting
routines approxiamte the entire data set by one single equation, rather
than with different equations in piecewise fashion.

Any suggestions?

--
Rouben Rostamian                          Telephone: (301) 455-2458
Department of Mathematics and Statistics  e-mail:
University of Maryland Baltimore County   bitnet: rostamian@umbc.bitnet
Baltimore, MD 21228,  U.S.A.              internet: rouben@math9.math.umbc.edu

rrd@hpfcso.HP.COM (Ray Depew) (02/06/91)

Rouben Rostamian  asks:

>How does one plot the graph of a function given in a tabular form?

>Specifically, I have a program that generates a sequence of (x,y)
>pairs and stores them in the stack.  The pairs represent points
>on the graph of the solution of a differential equation.
>Does anyone have a utility program for plotting a graph passing
>through these points?  A simple linear interpolation between the points
>will suffice.

Here's a quick program that will do what you want.  As with most
connect-the- dots scatter plots, the data points are connected in the 
same order they appear in your array.  This means that your output may
be ugly and disordered, unless you sort your array first.

I'm reading this from my 48 display and typing it in here, so pleaswe]
firgove typos.  You may be able to improve on this code, since I put
it together in only a few minutes.

Regards
Ray Depew
HP ICBD -- IC's by Bill and Dave   
rrd@hpfitst1.hp.com


TREND
-----
Draws a SCATTER plot and connects the dots.
Input:  Level 1:  A real array, or the name of a real array.
Output:  Nothing on the stack.  (Draws the plot and displays it.)
Caution:  Use [STAT] {XCOL} and [STAT] {YCOL} to choose your x- and
          y-data columns correctly. 
Checksum: #37143d
Bytes:  253.5

Instructions:  Use TREND instead of SCATRPLOT -- that is, use it the same way
you would use SCATRPLOT.  This means that you have to choose XCOL and YCOL 
before you start.  If you want to "pretty up" your plot, you can use LABEL,
AXES, DRAX and the other plotting functions to do so.

(In this listing, \GS is Sigma, or "Greek S".  Use [VARS] {\GSDAT}.     
                  \-> is "right arrow".  Use [Rshift][0],
                                          or [PRG]{OBJ}{\->LIST},
                                          or [PRG]{OBJ}[NXT]{R\->C}.
                  \=/ is "not equals".  Use [PRG]{TEST}[NXT]{\=/}.
)

\<< SCATRPLOT				@ To set plot limits and draw axes.
  IF DUP TYPE 3 \=/ THEN RCL END	@ Get the array on the stack.
  DUP SIZE 1 GET			@ Array length (number of rows).
  \GSPAR DUP 1 GET			@ x-data column no.
  SWAP 2 GET				@ y-data column no.
  \-> arry n xcol ycol
  \<< 1 n 1 - FOR j			@ Number of line segments to draw.
        arry DUP j xcol 2 \->LIST GET 
        OVER j ycol 2 \->LIST GET R\->C		@ First endpoint.
        OVER j 1 + xcol 2 \->LIST GET
        3 PICK j 1 + ycol 2 \->LIST GET R\->C	@ The other endpoint.
        LINE				@ Draw the line.
      NEXT
      { } PVIEW				@ Keep it in the display for as long
  \>>					@   as you want it.
\>>
    

rouben@math9.math.umbc.edu (Rouben Rostamian) (02/07/91)

Last week I posted an article inquiring if anyone had a program to plot
graphs of tabular data on the HP48.  
In article <7360065@hpfcso.HP.COM> rrd@hpfcso.HP.COM (Ray Depew) writes:
>Here's a quick program that will do what you want.
...

Nice program.  Works fast and it's easy to use.  Thank you very much.

After I had posted my query, I wrote a program to generate a cubic spline
interpolation of a given tabular data.  I can plot the function (and even
its derivative!)  It is slower than Ray Depew's program though :-(
I will post the program to this newsgroup in a couple of days after
I get a chance to load it into my workstation.

Regards,

Rouben Rostamian

--
Rouben Rostamian                          Telephone: (301) 455-2458
Department of Mathematics and Statistics  e-mail:
University of Maryland Baltimore County   bitnet: rostamian@umbc.bitnet
Baltimore, MD 21228,  U.S.A.              internet: rouben@math9.math.umbc.edu