Plotting the Graph of an Equation

See all articles from Update July 1989
Author(s): Warren Fricke
Publication: Update Magazine
Pub Details: Update July 1989
Date: July 1989
Pages: 20-21

The T/S 2068 is an ideal computer for plotting graphs of algebraic or trigonometric equations, for display purposes. Although its number of pixels available for high-resolution art work is a little less than the number in much more expensive computers, the Timex greatly offsets this minor deficiency for several important reasons. One is because the T/S plots in the first quadrant, which means that the origin is in the lower, left-hand corner making X measurements positive to the right and Y measurements positive up. This agrees with well-established, mathematical practice. The Apple IIe, a widely distributed computer in our schools, draws in an awkward fourth quadrant and measures Y values positive in the down direction. Another reason is the capability of the Timex to be able to mix high-resolution graphics with text in any arrangement on the screen and in any order within a program. The Apple, on the other hand, provides only a four-line window at the bottom of the screen for text. This hinders the need to place text in or around the drawing itself.

At this point it might be appropriate to admit to readers that some knowledge of geometry would be helpful in digesting this material, but it is not absolutely necessary. Most of this discussion will only involve simple arithmetic and measurement.

Perhaps the best way to explain how to plot a graph on the T/S computer is to go thru the usual steps one encounters using a sample equation. For this purpose consider the equation…….. Y=1/X.

Starting with an eye inspection, one can readily see that Y is negative for negative values of X, and that Y is positive for all positive values of X. Also note that Y becomes infinite when X equals zero. Thus the graph of this equation will lie in the first and third quadrants and its presentation will be enhanced by having its principal X- and Y-axes centered in the working area of the screen. So the first step is to relocate them from their left-hand and bottom positions.

For reasons which will soon become apparent, the distance of translation for these axes will be expressed in units of rows and/or columns, converted to the corresponding number of pixels, there being 8 pixels in the width of one row or one column. Thus the shift to the right for the Y-axis will be called X0 and will have a value in this example of 16 columns times 8 pixels per column. The upward shift of the X-axis will be called Y0 and have a value of 11 rows times 8 pixels per row.

Our next concern is scale. We have to enlarge the ordinates (Y values) and the abscissa (X values) of the curve to see it when plotted. Otherwise the curve would appear as nothing more than a few smudges around the intersection of the relocated axes. This part takes some practice. Errors in judgement, however, are easy to correct using the procedure recommended herein. In this example we will arbitrarily let 50 pixels represent 1 unit of X, the horizontal scale, and 10 pixels to represent 1 unit of Y, the vertical scale. It works out best to use multiples of ten, i.e., 10, 20, 30, etc. We will refer to these scale factors as SX and SY in the computer program coming up.

The program starts off with the initial lines devoted to putting a frame around the working area of the screen, plotting the relocated axes, and defining the arbitrary values previously discussed. Then a single FOR-NEXT loop is used to draw the graph itself. You may save yourself time by omitting the REM statements in your own keyboard entry.

4 LET X0=8*16: LET Y0=8*11
5 BORDER 6: REM ** DEFINES WORKING AREA
15 PLOT 5,Y0: DRAW 245,0
20 PLOT X0,5: DRAW 0,165
30 LET XS=50: LET YS=10
40 REM ** PLOTTING THE GRAPH
100 FOR X=-2 TO +2 STEP 0.1: REM ** ADJUST STEP LATER IF NECESSARY
110 LET Y=1/X: REM ** ORIGINAL EQUATION
120 LET XX=XS*X+X0
130 LET YY=YS*Y+Y0
140 IF X>-.2 AND X<+.2 THEN NEXT X: REM ** AVOID DIVISION BY 0
150 PLOT XX,YY: REM ** PLOT ADJUSTED VALUES
160 NEXT X
First plot of Y=1/X with STEP 0.1
First plot of Y=1/X with STEP 0.1

After running this program, you can see that we assumed reasonably good values for scale, but that the curve needs more plotted points for it to stand out better. Do this now by changing the STEP value in line 100 to a smaller one. The only other work required to complete the picture is to add the scale values to the axes so that one can read corresponding X and Y values off the graph… and a title. All of that is done by the addition of lines 170 to 420. Again, you can skip the REM statements in your copy to lessen the work.

2 REM ** GRAPH OF Y=1/X
3 REM ** "C-59A", 9-22-87
4 LET X0=8*16: LET Y0=8*11
5 BORDER 6: REM ** DEFINES WORKING AREA
15 PLOT 5,Y0: DRAW 245,0
20 PLOT X0,5: DRAW 0,165
30 LET XS=50: LET YS=10
40 REM ** PLOTTING THE GRAPH
100 FOR X=-2 TO +2 STEP 0.01: REM ** ADJUST STEP LATER IF NECESSARY
110 LET Y=1/X: REM ** ORIGINAL EQUATION
120 LET XX=XS*X+X0
130 LET YY=YS*Y+Y0
140 IF X>-.2 AND X<+.2 THEN NEXT X: REM ** AVOID DIVISION BY 0
150 PLOT XX,YY: REM ** PLOT ADJUSTED VALUES
160 NEXT X
170 REM ** FRAME THE DRAWING
180 PLOT 0,0: DRAW 255,0: DRAW 0,175: DRAW -255,0: DRAW 0,-175
190 REM ** HORIZ. HASH MARKS
200 FOR N=X0-100 TO X0+100 STEP 10
210 PLOT N,Y0+1: PLOT N,Y0+2
220 NEXT N
290 REM ** VERT. HASH MARKS
300 FOR N=Y0-60 TO Y0+60 STEP 10
310 PLOT X0+1,N: PLOT X0+2,N
320 NEXT N
390 REM ** SCALE VALUES & TEXT
400 PRINT AT 9,2;"-2";TAB 8;"-1";AT 9,29;"X";AT 11,15;"0";AT 11,22;"1";TAB 28;"2"
410 PRINT AT 1,15;"Y";AT 4,15;"5";AT 17,17;"-5"
420 PRINT AT 20,17;"GRAPH OF Y=1/X"
Finished graph of Y=1/X with scale values and title
Finished graph of Y=1/X with scale values and title

Note that the graph is self-contained and that it has all of the information needed to stand alone.

In some future article we will explore how this concept of graph drawing can be applied to other mathematical curves besides the rectangular hyperbola (Y=1/X) which was used here.

Warren Fricke


A Fun Contest

Kilroy is the legendary sneaky Pete of World War II. “Kilroy was here” could be seen everywhere in little signs all over the USA, Canada, Europe and Asia. It is said that when Gen. McArthur stepped foot on Japan for the first time he saw the note “Kilroy was here”. No one ever saw Kilroy in the present tense. He was always there “before”. Hitler thought that Kilroy was a master Spy and had a general order out for his capture. Talk about computer viruses! Kilroy weaseled his way into the prges of Update. He was there and gone as usual. Find where he was just for the fun of it. The first letter received that tells” where Kilroy was” will receive honorable mention in the next issue.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.