Discussion:
HP 48gx programming
(too old to reply)
m***@gmail.com
2018-10-19 06:14:53 UTC
Permalink
Note:
I don't know where this message is delivered.

However, anyone reading this, please help me. I'd like to add this program to my HP48GX.
It is for solving a system of linear equations. I plan to use it in my course of Electric Circuits (implies phasors and matrixes).

If anyone there can help me checking this code, please explain me how to enter it on the calculator because I don't understand the syntax at all.


The code is:
%%HP: T(2)A(D)F(.);
DIR
·\<-
« VARS 1 OVER
'·\<-' POS 1 - SUB
PURGE
»
SYS
« DUP SIZE \-> l
n
« n \->LIST
'EQS' STO 0 n
FOR i 1 n
FOR j i j
== 1 0 IFTE l j GET
STO
NEXT 1 n
FOR j '
EQS(j)' \->NUM
NEXT n
\->ARRY i
IF NOT
THEN NEG
'VET' STO
ELSE VET
+ ARRY\-> DROP
END
NEXT { n n
} \->ARRY l PURGE TRN
CONJ 'MAT' STO VET
MAT / n 1
FOR i DUP i
GET \->Q l i GET STO
-1
STEP DROP
MAT VET n 1 + COL+
'MAT' STO 'VET'
PURGE
»
»
END

Source and credits: http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv015.cgi?read=82010


PS. I don't have the PC adapter for the calc, therefore I need to do it all manually.

Thanks for investing time reading this.
-Mateo
elturco
2018-10-19 14:45:17 UTC
Permalink
Start copying from DIR (DIR included), and pay attention to the spaces it should work.
Isaac Mateo Sarzosa Valencia
2018-10-20 20:39:59 UTC
Permalink
Thanks so much for replying.

What does '\•<-' mean?

Especially the upper-mid dot.
Scott Hemphill
2018-10-20 21:22:35 UTC
Permalink
Post by Isaac Mateo Sarzosa Valencia
Thanks so much for replying.
What does '\•<-' mean?
Especially the upper-mid dot.
You don't have those characters in the correct order. It should be

'•\<-'

Whenever you encounter a backslash, it begins a three character code
that describes a single HP48 character. \<- is the visible left arrow
character. The single quotes surround a variable name, which in this
case is comprised of a center dot and a left arrow. This is the name of
a function, which is defined as part of the directory.

Scott
--
Scott Hemphill ***@alumni.caltech.edu
"This isn't flying. This is falling, with style." -- Buzz Lightyear
Bruce Horrocks
2018-10-24 16:05:18 UTC
Permalink
Post by Scott Hemphill
Post by Isaac Mateo Sarzosa Valencia
Thanks so much for replying.
What does '\•<-' mean?
Especially the upper-mid dot.
You don't have those characters in the correct order. It should be
'•\<-'
Whenever you encounter a backslash, it begins a three character code
that describes a single HP48 character. \<- is the visible left arrow
character. The single quotes surround a variable name, which in this
case is comprised of a center dot and a left arrow. This is the name of
a function, which is defined as part of the directory.
The suggestion to start from the DIR and go to the END omitted to
mention that this just gives you a directory object on the stack. You'll
then need to to STO it - which will create a sub-directory.

E.g.
DIR A 33 END
'ZZ' STO

will create a sub-directory called ZZ in the current directory and it
will contain a variable 'A' containing the value 33.

Also, the HP Museum thread notes that the program as listed won't work
on the 48G (because it uses the COL+ command) and an alternate version
is supplied. I've incorporated that below.

The program as listed is actually two, so it might be easier just to
enter those one at a time and STO them individually.

First program:

« VARS 1 OVER '·\<-' POS 1 - SUB PURGE »
'.\<-' STO

(To enter '.\<-' I suggest pressing ' then CHARS then select char 183
ECHO followed by char 142 ECHO)

WARNING: DO NOT RUN THE .\<- PROGRAM AS IT WILL DELETE ALL YOUR
VARIABLES INCLUDING THE FOLLOWING 'SYS' PROGRAM WHICH TAKES AN AGE TO
ENTER ON THE CALCULATOR!!! Just delete the variables manually when you
move to a new problem.

Second program:

«
DUP SIZE \-> l n
«
n \->LIST 'EQS' STO
0 n FOR i
1 n FOR j
i j == 1 0 IFTE
l j GET STO
NEXT
1 n FOR j
'EQS(j)' \->NUM
NEXT
n \->ARRY
i IF NOT THEN
NEG 'VET' STO
ELSE
VET + ARRY\-> DROP
END
NEXT
{ n n } \->ARRY
l PURGE
TRN CONJ 'MAT' STO
VET MAT /
n 1 FOR i
DUP i GET l i GET STO
-1 STEP
VET ARRY\-> DROP {n 1} \->ARRY
'VET' STO DROP
»
»

'SYS' STO


They aren't the best written programs in the world because (a) one uses
PURGE (which is asking for trouble at the best of times) to remove all
variables from the current directory (except itself) (except it doesn't)
so use a separate directory (from your other work) to store both in
otherwise you WILL lose work; and (b) the second creates variables which
is not best practice - mostly because they're hard to clean up safely.

The PURGE in the ./<- program simply doesn't work as intended. At the
very least it needs to check for '.\<-' and 'SYS' and not purge those.

Also the line "i j == 1 0 IFTE" could become "i j ==" since the IFTE is
only returning true or false (1/0) which the == command does anyway.

Hmm.
--
Bruce Horrocks
Surrey
England
(bruce at scorecrow dot com)
Loading...