(Free42 or possibly 42s with printer) Larger graphing area - now with PLOTR graphing
02-06-2022, 12:12 AM (This post was last modified: 02-14-2022 03:51 AM by arhtur.)
Post: #1
 arhtur Junior Member Posts: 14 Joined: Jun 2021
(Free42 or possibly 42s with printer) Larger graphing area - now with PLOTR graphing
From the first time I saw a HP 42s, I was surprised to hear that equations could be plotted on the tiny 2 line screen. On the Free42, it is possible to print the LCD to a virtual “printout”. By combining 6 calls to PRLCD, we can have a larger 131x96 area to plot pixels.

The bitmap of the pixels is stored in a 12 row by 131 column matrix where each element has an 8 bit number. Calls to STOIJ, RCLEL and STOEL make it possible to set pixels within a specific portion of the matrix.

There are 2 examples that graph the sine function (XEQ SG) and produce a checkerboard pattern (XEQ CB).

However, if you want to plot points on your own, first XEQ XYINIT to initialize the matrix.

Then, put the Y coordinate (between 0 and 95) and the X coordinate (between 0 and 130) on the stack. Then XEQ XYP. No checks are made for valid coordinates.

To “print” the graph, XEQ XYG. Because the Alpha register only holds 44 characters (on the Free42), 6 calls to AGRAPH are necessary to fill the entire LCD (3 times across and twice for the 1st and 2nd row of 8 pixels). To have a graph that is 96 pixels tall, PRLCD is called 6 times.

On the Free42, in order to see the graph, tap the LCD portion of the calculator and select “Show Print-Out”. When done, tap “Done”. You will have to press EXIT (ON) to exit the blank calculator screen. This has not been tested on the 42s with a printer, since I don't have a printer.

Code:
00 { 408-Byte Prgm } 01▸LBL "XYINIT" 02 12 03 132 04 NEWMAT 05 STO "M" 06 RTN 07▸LBL "XYP" 08 INDEX "M" 09 X<>Y 10 STO "Y" 11 8 12 ÷ 13 IP 14 1 15 + 16 X<>Y 17 1 18 + 19 STOIJ 20 RCLEL 21 1 22 RCL "Y" 23 8 24 MOD 25 +/- 26 ROTXY 27 OR 28 STOEL 29 RTN 30▸LBL "XYG" 31 CLLCD 32 1.044 33 STO "X" 34 1.012 35 STO "Y" 36 CLA 37▸LBL "XYG1" 38 INDEX "M" 39 RCL "Y" 40 RCL "X" 41 STOIJ 42 RCLEL 43 XTOA 44 ISG "X" 45 GTO "XYG1" 46 1 47 1 48 AGRAPH 49 CLA 50 45.088 51 STO "X" 52▸LBL "XYG2" 53 INDEX "M" 54 RCL "Y" 55 RCL "X" 56 STOIJ 57 RCLEL 58 XTOA 59 ISG "X" 60 GTO "XYG2" 61 1 62 45 63 AGRAPH 64 CLA 65 89.132 66 STO "X" 67▸LBL "XYG3" 68 INDEX "M" 69 RCL "Y" 70 RCL "X" 71 STOIJ 72 RCLEL 73 XTOA 74 ISG "X" 75 GTO "XYG3" 76 1 77 89 78 AGRAPH 79 1 80 STO+ "Y" 81 CLA 82 1.044 83 STO "X" 84▸LBL "XYG4" 85 INDEX "M" 86 RCL "Y" 87 RCL "X" 88 STOIJ 89 RCLEL 90 XTOA 91 ISG "X" 92 GTO "XYG4" 93 9 94 1 95 AGRAPH 96 CLA 97 45.088 98 STO "X" 99▸LBL "XYG5" 100 INDEX "M" 101 RCL "Y" 102 RCL "X" 103 STOIJ 104 RCLEL 105 XTOA 106 ISG "X" 107 GTO "XYG5" 108 9 109 45 110 AGRAPH 111 CLA 112 89.132 113 STO "X" 114▸LBL "XYG6" 115 RCL "Y" 116 RCL "X" 117 STOIJ 118 RCLEL 119 XTOA 120 ISG "X" 121 GTO "XYG6" 122 9 123 89 124 AGRAPH 125 PRLCD 126 CLLCD 127 CLA 128 1.044 129 STO "X" 130 ISG "Y" 131 GTO "XYG1" 132 RTN 133 END

Plotting feature: Now I’ve added the PLOTR program that makes it easier to plot graphs. The variables XMIN, XMAX, YMIN and YMAX must be set. -10 and 10 are good starting points for the min and max values. Also, FN must hold the function to be graphed. FN must take the X value on the stack and return the Y value on the stack. For example, to plot the sine graph:

LBL FN
SIN
RTN

To graph y=2x + 3:

LBL FN
2
x (times)
3
+
RTN

The plotter will first draw the draw the X axis (DRX) and then draw the Y axis (DRY). There is no scale to the drawn dashes (they are just 8 pixels apart). If you are using X and Y min and max values that do not include the axis, you can skip drawing the axis by calling PLT01.

For a single graph, store the min and max values and the function (FN),
XEQ XYINIT
XEQ PLOTR
XEQ XYG
Tap the screen and select “Show Print-Out”.

For multiple graphs,
1. XEQ XYINIT
2. Define function in FN
3. XEQ PLOTR (PLOTR can be called the first time, but for subsequent graphs XEQ PLT01 to avoid the axis drawing erasing part of the original graph)
Repeat steps 2 and 3 for subsequent functions.
XEQ XYG
Tap the screen and select “Show Print-Out”

Of course there is the limitation that a function like ln(x) cannot be graphed for x<=0. The tangent function seemed to work for me.

PLOTR program:

Code:
00 { 390-Byte Prgm } 01▸LBL "PLOTR" 02 GTO "DRX" 03▸LBL "DRY" 04 RCL "XMIN" 05 +/- 06 RCL "XMAX" 07 RCL "XMIN" 08 - 09 ÷ 10 131 11 × 12 IP 13 STO "X" 14 1.012 15 STO "Z" 16▸LBL "PLT0" 17 INDEX "M" 18 RCL "Z" 19 RCL "X" 20 STOIJ 21 254 22 STOEL 23 ISG "Z" 24 GTO "PLT0" 25 GTO "PLT01" 26▸LBL "DRX" 27 RCL "YMAX" 28 RCL "YMAX" 29 RCL "YMIN" 30 - 31 ÷ 32 95 33 × 34 IP 35 STO "X" 36 8 37 ÷ 38 1 39 + 40 STO "Y" 41 1 42 RCL "X" 43 8 44 MOD 45 +/- 46 ROTXY 47 STO "N" 48 1.131 49 STO "Z" 50▸LBL "PLT00" 51 RCL "Z" 52 IP 53 8 54 MOD 55 X=0? 56 GTO "PLT02" 57 INDEX "M" 58 RCL "Y" 59 RCL "Z" 60 STOIJ 61 RCL "N" 62 STOEL 63▸LBL "PLT02" 64 ISG "Z" 65 GTO "PLT00" 66 GTO "DRY" 67▸LBL "PLT01" 68 RCL "XMAX" 69 RCL "XMIN" 70 - 71 131 72 ÷ 73 STO "STP" 74 0.130 75 STO "Z" 76 RCL "XMIN" 77 STO "X" 78▸LBL "PLT1" 79 RCL "XMIN" 80 RCL "Z" 81 RCL "STP" 82 × 83 + 84 XEQ "FN" 85 +/- 86 RCL "YMAX" 87 + 88 96 89 × 90 RCL "YMAX" 91 RCL "YMIN" 92 - 93 ÷ 94 STO "N" 95 95 96 X<Y? 97 GTO "PLT2" 98 RCL "N" 99 0 100 X>Y? 101 GTO "PLT2" 102 RCL "N" 103 RCL "Z" 104 XEQ "XYP" 105▸LBL "PLT2" 106 ISG "Z" 107 GTO "PLT1" 108 RTN 109 END

Sine Graph:

Code:
00 { 136-Byte Prgm } 01▸LBL "SG" 02 DEG 03 0.131 04 STO "Z" 05 XEQ "XYINIT" 06▸LBL "SINEG1" 07 RCL "Z" 08 IP 09 6 10 × 11 SIN 12 24 13 × 14 +/- 15 48 16 + 17 RCL "Z" 18 IP 19 XEQ "XYP" 20 48 21 RCL "Z" 22 IP 23 XEQ "XYP" 24 ISG "Z" 25 GTO "SINEG1" 26 4.009 27 STO "Z" 28▸LBL "SINEG2" 29 INDEX "M" 30 RCL "Z" 31 61 32 STOIJ 33 255 34 STOEL 35 ISG "Z" 36 GTO "SINEG2" 37 XEQ "XYG" 38 RTN 39 END

Checkerboard pattern:

Code:
00 { 155-Byte Prgm } 01▸LBL "CB" 02 XEQ "XYINIT" 03 3.01 04 STO "A" 05 2.005 06 STO "B" 07▸LBL "CBOARD1" 08 RCL "B" 09 16 10 × 11 RCL "A" 12 2 13 MOD 14 8 15 × 16 + 17 STO "C" 18 0.007 19 STO "D" 20▸LBL "CBOARD2" 21 INDEX "M" 22 RCL "A" 23 RCL "C" 24 STOIJ 25 255 26 STOEL 27 1 28 STO+ "C" 29 ISG "D" 30 GTO "CBOARD2" 31 ISG "B" 32 GTO "CBOARD1" 33 2.005 34 STO "B" 35 ISG "A" 36 GTO "CBOARD1" 37 XEQ "XYG" 38 RTN 39 END
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)