The Museum of HP Calculators

HP Forum Archive 14

[ Return to Index | Top of Index ]

Help needed with a matrix
Message #1 Posted by Karl-Ludwig Butte on 7 Aug 2004, 12:06 p.m.

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)
Message #2 Posted by Vieira, Luiz C. (Brazil) on 7 Aug 2004, 3:13 p.m.,
in response to message #1 by Karl-Ludwig Butte

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
Message #3 Posted by Veli-Pekka Nousiainen on 8 Aug 2004, 4:30 a.m.,
in response to message #1 by Karl-Ludwig Butte

[[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
Message #4 Posted by Karl-Ludwig Butte on 10 Aug 2004, 3:04 a.m.,
in response to message #1 by Karl-Ludwig Butte

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
Message #5 Posted by James M. Prange on 10 Aug 2004, 11:18 a.m.,
in response to message #4 by Karl-Ludwig Butte

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
Message #6 Posted by Karl-Ludwig Butte on 11 Aug 2004, 4:36 a.m.,
in response to message #5 by James M. Prange

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.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall