Matrix in program

Discussion around the SwissMicros DM42 calculator
Post Reply
User avatar
rudi
Posts: 413
Joined: Wed Nov 03, 2021 9:03 am
Location: Denmark
Contact:

Matrix in program

Post by rudi »

Is it possible to somehow include a matrix in a program?

Something like this:

Code: Select all

01 LBL "TEST"
02 MATRIX[[0,1,2],[3,4,5],[6,7,8]]
03 END
/Rudi

DM-42 (s/n 06999), HP-42S, HP-35s, HP-11c, HP-32SII (ex HP-41CV, ex HP-75C, ex HP-48G + a lot, really lot of a accessories)
Denmark
Thomas Okken
Posts: 1098
Joined: Tue May 02, 2017 5:48 pm
Location: Netherlands
Contact:

Re: Matrix in program

Post by Thomas Okken »

No, the best you can do is use the usual matrix functions to create and populate the matrix. Which is still pretty efficient, but not very elegant:

Code: Select all

00 { 48-Byte Prgm }
01▸LBL "M"
02 3
03 ENTER
04 NEWMAT
05 EDIT
06 0
07 →
08 1
09 →
10 2
11 →
12 3
13 →
14 4
15 →
16 5
17 →
18 6
19 →
20 7
21 →
22 8
23 EXITALL
24 END
User avatar
rudi
Posts: 413
Joined: Wed Nov 03, 2021 9:03 am
Location: Denmark
Contact:

Re: Matrix in program

Post by rudi »

Thanks Thomas, just as I figured ;-) Was hoping, that there was a new smart feature in DM42 that I had overlooked ;-)
I need a rather large matrix (1x1000+) to store some hard coded numbers in and hoped for the "elegant" solution ;-)

But I guess that I can store a lazy initialized matrix in memory, and create it at runtime if it is missing.

Code: Select all

01 LBL "TEST"
02 SF 25    @Ignore errors
03 RCL "MatrixX" @Will fail if Nonexistent, but how to detect?
...
04 if "MatrixX" doesn't exist, then
05 XEQ 00  @create and initialize "MatrixX"
However, even if it is possible, I do not like this solution, since it ends up having the numbers doubled up in memory, 1x in the code and 1x in the matrix. I will try thinking of another way.
/Rudi

DM-42 (s/n 06999), HP-42S, HP-35s, HP-11c, HP-32SII (ex HP-41CV, ex HP-75C, ex HP-48G + a lot, really lot of a accessories)
Denmark
Florian
Posts: 22
Joined: Mon Apr 26, 2021 1:19 pm
Location: Japan

Re: Matrix in program

Post by Florian »

Quoting from the HP-42S Owner's Manual, Appendix C: Flags
You can detect an error by setting flag 25 just before an instruction
and then testing the flag after the instruction to see if it has been
cleared. (Generally, you should test and clear flag 25—you risk los-
ing data if you choose to ignore unanticipated errors.) This enables
a program to branch rather than to stop execution in case of an
error.
:D
User avatar
rudi
Posts: 413
Joined: Wed Nov 03, 2021 9:03 am
Location: Denmark
Contact:

Re: Matrix in program

Post by rudi »

Thanks Florian - embarasing that I didn't remember this and even more, that I didn't bother to read the HP-42S manual ;-)
I'll use FC?C to ensure that Flag 25 is cleared after the test, to avoid it remaining set and causing undesired errors ahead.

Code: Select all

01 LBL "TEST"
02 SF 25    @Ignore errors
03 RCL "MatrixX"
04 FC?C 25
05 XEQ 00  @create and initialize "MatrixX"
...
/Rudi

DM-42 (s/n 06999), HP-42S, HP-35s, HP-11c, HP-32SII (ex HP-41CV, ex HP-75C, ex HP-48G + a lot, really lot of a accessories)
Denmark
Florian
Posts: 22
Joined: Mon Apr 26, 2021 1:19 pm
Location: Japan

Re: Matrix in program

Post by Florian »

Glad I could be of help.

Still, I am with you in hoping that one day there might be a more ... compact ... way of including matrix data in programs. :)
User avatar
Guenter
Posts: 168
Joined: Wed May 24, 2017 6:26 pm
Location: Germany

Re: Matrix in program

Post by Guenter »

rudi wrote:
Thu Jan 27, 2022 6:18 am

However, even if it is possible, I do not like this solution, since it ends up having the numbers doubled up in memory, 1x in the code and 1x in the matrix. I will try thinking of another way.
I think you could create a program just for creating the hard-coded matrix. Once it is done you could delete this program, backup on your computer in case ... Then you have the matrix available as a variable and any program can access it as you like.

Günter
Günter
DM42 SN:00004 and SN:00184 -- DM41X SN:00013 and SN:00955
bob38
Posts: 2
Joined: Tue Aug 24, 2021 3:00 am

Re: Matrix in program

Post by bob38 »

How to Add a Big Matrix to the DM42 from a Computer

Reference: https://thomasokken.com/free42
"Loading, Saving, and Switching States"
"The Hidden Powers of Copy and Paste"
"Matrices"

Well, I wouldn't want to have to do this frequently, but it should have worked for
my purposes, except that at Step #12 below I got the DM42 error "State File Too New".
I'm guessing that I have to install a more recent version of something on my DM42,
which I'll do when my mind is a little fresher.

This is what I did:

1. Compose/save the matrix in file "mymatrix.tsv" in any text editor on my computer.
Columns are tab-delimited, rows are newline-delimited.
2. Save the state of my DM42 to file "OLD.f42" on my DM42.
3. Activate USB disk between my DM42 and my computer.
4. Copy file "OLD.f42" to my computer.
5. Launch Free42 (either "Decimal" or "Binary") on my computer.
6. Under menu "File / States...", Import file "OLD.f42".
7. In the text editor on my computer, copy file "mymatrix.tsv" to the copy/paste buffer.
8. Paste to Free42. Matrix in now in X on Free42.
9. Optional step: store X in some global variable in Free42.
10. Save the state of Free42 to file "NEW.f42" on my computer.
11. Copy file "NEW.f42" from computer to DM42 via USB disk.
12. Deactivate USB disk between computer and DM42.
13. Restore the state of my DM42 from file "NEW.f42".
The only change to the DM42 is the new matrix.
14. Cleanup: delete files "OLD.f42" & "NEW.f42" on DM42.
bob38
Posts: 2
Joined: Tue Aug 24, 2021 3:00 am

Re: Matrix in program

Post by bob38 »

How to Add a Big Matrix to the DM42 from a Computer

Reference: https://thomasokken.com/free42
"Loading, Saving, and Switching States"
"The Hidden Powers of Copy and Paste"
"Matrices"

Well, I wouldn't want to have to do this frequently, but it should have worked for
my purposes, except that at Step #12 below I got the DM42 error "State File Too New".
I'm guessing that I have to install a more recent version of something on my DM42,
which I'll do when my mind is a little fresher.

This is what I did:

1. Compose/save the matrix in file "mymatrix.tsv" in any text editor on my computer.
Columns are tab-delimited, rows are newline-delimited.
2. Save the state of my DM42 to file "OLD.f42" on my DM42.
3. Activate USB disk between my DM42 and my computer.
4. Copy file "OLD.f42" to my computer.
5. Launch Free42 (either "Decimal" or "Binary") on my computer.
6. Under menu "File / States...", Import file "OLD.f42".
7. In the text editor on my computer, copy file "mymatrix.tsv" to the copy/paste buffer.
8. Paste to Free42. Matrix in now in X on Free42.
9. Optional step: store X in some global variable in Free42.
10. Save the state of Free42 to file "NEW.f42" on my computer.
11. Copy file "NEW.f42" from computer to DM42 via USB disk.
12. Deactivate USB disk between computer and DM42.
13. Restore the state of my DM42 from file "NEW.f42".
The only change to the DM42 is the new matrix.
14. Cleanup: delete files "OLD.f42" & "NEW.f42" on DM42.
Post Reply