HP Forums
Help needed with a matrix - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: Help needed with a matrix (/thread-61614.html)



Help needed with a matrix - Karl-Ludwig Butte - 08-07-2004

I need some help with the programmatic creation of a matrix as well as storing and recalling values to it. I created a matrix with the following steps:

[[12. 2.] [0. 0. ]]
'MAT'
STO

This worked and created the matrix named "MAT". Then I tried to insert a row after the row [12. 2.] with the string "ABC" and the value 2004. I succeeded by entering the following in RUN-Mode:

MAT (resulting in recalling the matrix MAT to the stack)
['ABC' 2004]
2
ROW+

Now doing the same from within a UserRPL program with a slight modification always results in an error. The modification ist that the value 2004 should come from a local variable named n:

[[12. 2.] [0. 0. ]]
'MAT'
STO
MAT
['ABC' n]
2
ROW+

This results in a syntax error. All my attempts to create ['ABC' 2004] on the stack with 2004 coming from variable n failed. The users manual from the CD was no help at all (how I wish back the times when HP really could be proud of their user manuals like the one for the HP-67/97).

Later on in the program I need to recall individual values from the matrix as well as storing new values in already existing cells.

How can I acomplish these task ? Maybe there is a really good tutorial somewhere on the Internet ? Any hint will be very much appreciated - thank you very much in advance.


Re: Help needed with a matrix (edited) - Vieira, Luiz C. (Brazil) - 08-07-2004

Hi, Karl;

I used an HP49G+, O.K.? I tried this and it worked:

[[12. 2.] [0. 0. ]]
'MAT'
STO
MAT
[['ABC' n]]
2
ROW+

The resulting object is:

[[12. 2.]
[ABC n]
[0. 0. ]]

Note that the object to be added as a new row is a matrix. It seems that ROW+ expects a matrix (or a single-row matrix) instead of a 2-D vector.

Hope this helps.

Luiz (Brazil)


Edited: 7 Aug 2004, 4:10 p.m.


Re: Help needed with a matrix - V-PN - 08-08-2004

[[12. 2.] [0. 0. ]] 'MAT' STO MAT ['ABC' n] 2 ROW+
==================================================
...
2004 -> n <<
[[12. 2.] [0. 0. ]] 'MAT' STO MAT
'ABC' n 2 ->ARRY 2 ROW+
>> @ now the value of n is there
[[VPN]]



Re: Help needed with a matrix - Karl-Ludwig Butte - 08-10-2004

Thanks both of you for your answers. The solutions work like a charm. I'm going to use this for a short routine that can be used to log values of local variables for debugging and reference purposes. By the way, is there a method of detecting the presence of a global matrix variable ? For the short routine I'm planning I need to know if the matrix already exits or if the program has to create it first ?


Re: Help needed with a matrix - James M. Prange (Michigan) - 08-10-2004

You could probably just use:

'VarName' STO
If VarName already exists in the current directory, then it will be overwritten, if it doesn't exist in the current directory, then it will be created.

But if you want to avoid overwriting VarName, use the VTYPE command.

'VarName' VTYPE
returns the type of object stored in the variable if it's found, or -1 if it doesn't exist in the current path.


Re: Help needed with a matrix - Karl-Ludwig Butte - 08-11-2004

Thank you, James, the second method you describe is the one of choice in this case 'cause I wouldn't want to overwrite an existing matrix.