( 14 )
Previous Table Of Contents Next


Plots

You would think that I would be tired of the SecondOrderEq series of example programs by now, but this old calculator still has a few surprises in store for us. You see, I have converted this 1970's calculator into a graphing calculator. Graphing calculators are still sold today, but they don't impress me because of their limited screen size, their lack of color, their inability to print the graph, their inability to store the graph (say in a .GIF or .BMP file) so that it can be imported into a word processor document, etc. But Windows programs do not have these limitations. So I decided to link my RPN calculator to another window that can host a plot of the data points provided by the calculator. You have already seen this cGraph window, as I employed it to demonstrate the least squares curve fits.

The linkage between the RPN calculator and the cGraph window consists of only 3 keystrokes: ClearG, SumG, and SetG. Any time you hit the ClearG key () all data points are removed from the cGraph window. Any time you hit the SumG key () the contents of the X and Y stack locations are employed as an (x,y) data point which is added to the curve. The SetG key () takes a single operand which specifies which of the overlaid curves in the cGraph window should be made active. After the ClearG keystroke the #1 data curve ( also called a "data line") is made active. As you continue to employ the SumG keystrokes your data points will be added to this #1 curve. If you want a second curve to be overlaid on the same plot then use the keystroke sequence 2, SetG. This activates curve #2. The SumG keystroke now accumulates data points onto curve #2. After adding some data points to curve #2 you can still add more data points to curve #1 by first employing the 1, SetG keystroke sequence.

The legal range for the operand of the SetG keystroke keeps changing. Immediately after a ClearG keystroke the only legal operand for the SetG keystroke is the value 1. Of course, you don't need to issue this SetG command since its consequence has already been accomplished by the ClearG keystroke. But once you have added at least 1 data point to curve #1 you can now legally employ an operand value of either 1 or 2 with the SetG key. And after you have added at least 1 data point to curve #2 you can legally employ an operand value of 1, 2, or 3 with the SetG key. Got it?

Let's practice by manually constructing a plot. Start by issuing the ClearG keystroke so we know that the graphics subsystem has been cleared. Then type:

2 ENTER 1 SumG

As soon as you typed the SumG keystroke the cGraph window became visible (if it hadn't already been visible). Anytime you want to control the visibility of the cGraph window you can employ the View/Graph option found on the menu bar. Our graph currently consists of only a single data curve (curve #1) with the single data point (x,y) = (1,2). Let's now add a second data point (x,y) = (2,3) to this same curve:

3 ENTER 2 SumG

Now that the data curve has at least two points the cGraph window can draw a line between them. By default, the cGraph window is in its auto-range mode which means that it continually chooses the range for the x and y axes so as to fit the data points it has been given. Any time you would like to control the range of the x and y axes you can RIGHT click on the cGraph window and select "Reformat Plot..." from the context menu (i.e., the right-click menu). The plot range will then be fixed until you again select "Auto Range" from the cGraph's context menu. I will not try to cover all of cGraph's capabilities here, as it has its own help pages which you can access via the Help/Help menu choice on its menu bar.

Let's now overlay a second data curve. To do this we first type:

2 SetG

to activate curve #2. We can then add two data points to curve #2:

5 ENTER 3 SumG 4 ENTER 4 SumG

At this point your cGraph window will look like:

By playing around with the options available on cGraph's context menu you can transform this rather plain looking graph into something like:

Now that we have met the cGraph window let's programmatically spit data points at it. My SecondOrderEq6.txt example program does exactly this.

; file SecondOrderEq6.txt ; This RPN calculator program computes and plots ; the second order eq.: ; y = f(x) = 1x^2 + 2x + 3 ; for an infinite sequence of x values starting with ; whatever x value was placed into the X stack location ; before the program was initiated. ; To run the program initialize the X stack location with ; an x axis value and then type GSB 0 (alternatively, ; type GTO .00 followed by R/S). Each new data point will ; have an x axis value 1 larger than the prior data point. ; This program employs Reg[0] to hold the sequence of x values. LBL 0 ; program entry point, at this time X = x STO 0 ; preserve initial x value in Reg[0] ClearG ; clear any prior graph LBL 1 ; we loop back to here for each new computation x^2 ; X = x^2 +2. ; X = 2, Y = x^2 ENTER ; X = 2, Y = 2, Z = x^2 RCL 0 ; X = x, Y = 2, Z = x^2 * ; X = 2x, Y = x^2 +3. ; X = 3, Y = 2x, Z = x^2 + ; X = 2x+3, Y = x^2 + ; X = x^2+2x+3 = y RCL 0 ; prepare for SumG by arranging X = x, Y = y SumG ; add data point to graph (this statement also ; opens the cGraph window) +1. ; increment x by 1 + STO 0 ; save new x GTO 1 ; loop back for another iteration

Notice that SecondOrderEq6.txt has a SumG statement in the spot where SecondOrderEq5.txt had a PAUSE statement and SecondOrderEq4.txt had a R/S statement.

After loading this program I would suggest you start it via the keystroke sequence: -500 GSB 0; that is:

The program will then run forever, sketching out an ever increasing parabola. If you don't like watching all the jitter caused by cGraph's continual auto-ranging to the latest data, simply select the plot axes yourself using cGraph's "Reformat Plot..." context menu choice and then re-run the program. For example, for the horizontal axis select 5 tick marks with a minimum tick of -500 and a maximum tick of 500. For the vertical axis select 6 tick marks with a minimum tick of 0 and a maximum tick of 200000. Then re-run the program from the start with an initial x axis value of -500. Remember that this program runs forever. We will have yet one more version of this long-running series of SecondOrderEq example programs and that one will know how to stop after generating some reasonable number of data points.


Previous Table Of Contents Next