cancel
Showing results for 
Search instead for 
Did you mean: 
joeres
Level 1
6 5 1 1
Message 1 of 13
1,132
Flag Post

Solved!

HP 50g - create matrix variable with userrpl and run matrix writer

HP Recommended
HP 50g
Other

Hello together,

 

i like to create a multipication table and save this in a matrix variable. Afterwards i like to run the matrix writer with the created matrix variable. Have someone a idea how can this make this a userrpl script? At least, ceate a multipication table via userrpl?

 

Many thanks for help.

 

Kind regards

joeres

0 Kudos
Tags (2)
12 REPLIES 12
Maké
Level 9
3,551 3,490 180 541
Message 2 of 13
Flag Post
HP Recommended

Hi!, joeres:

 

Welcome to HP Forum !. :generic:

 

Can you explained better with an example, for your question ?. 

Kind Regards !.
Have a nice day !.
@Maké (Technical Advisor Premium - HP Program Top Contributor).
Provost in HP Spanish Public Forum ... https://h30467.www3.hp.com/
0 Kudos
joeres
Author
Level 1
6 5 1 1
Message 3 of 13
Flag Post
HP Recommended

Hi Maké,

 

thanks for you answer.

 

Ok, i like to create a UserRPL script that automatically create a matrix variable. The content of the matrix variable is also generated by the script, e.g. this multiplication table:

×     1     2     3     4     5     6     7     8     9     10     11     12
1     1     2     3     4     5     6     7     8     9     10     11     12
2     2     4     6     8     10     12     14     16     18     20     22     24
3     3     6     9     12     15     18     21     24     27     30     33     36
4     4     8     12     16     20     24     28     32     36     40     44     48
5     5     10     15     20     25     30     35     40     45     50     55     60
6     6     12     18     24     30     36     42     48     54     60     66     72
7     7     14     21     28     35     42     49     56     63     70     77     84
8     8     16     24     32     40     48     56     64     72     80     88     96
9     9     18     27     36     45     54     63     72     81     90     99     108
10     10     20     30     40     50     60     70     80     90     100     110     120
11     11     22     33     44     55     66     77     88     99     110     121     132
12     12     24     36     48     60     72     84     96     108     120     132     144

 

Or in a other case, a UserRPL script generate random values, e.g.:

×     1     2     3     4
1     3     5     8     1
2     7     9     6     4
3     4     2     2     2
4     9     1     0     5
5     3     7     1     7
6     2     9     4     6

 

After generating the matrix variable with the content through the UserRPL script, the tool "Matrix writer" (APPS 8 F6) should be startet automaticlly, also through the UserRPL script and the Matrix writer shows the content of the generated matrix variable.  

 

I have no ideas, how we can make it.

 

Hope, this helps.

 

Thanks and kind regards,

joeres

0 Kudos
Maké
Level 9
3,551 3,490 180 541
Message 4 of 13
Flag Post
HP Recommended

Hi!, @joeres:

 

See, this link, if serve for you ... http://h20564.www2.hp.com/hpsc/doc/public/display?docId=emr_na-c01941333-1

Kind Regards !.
Have a nice day !.
@Maké (Technical Advisor Premium - HP Program Top Contributor).
Provost in HP Spanish Public Forum ... https://h30467.www3.hp.com/
0 Kudos
Jan_D
Level 6
305 297 32 76
Message 5 of 13
Flag Post
HP Recommended

Did you read the user guide?

http://h10032.www1.hp.com/ctg/Manual/c00748644

 

Suppose M is the matrix you want to use.

Then you first have to create a matrix which has the right number of rows and columns.

Suppose you want to have 6 rows and 7 columns, then you could use CON({6,7},0) to create such a matrix with all elements being 0, and store it in variable M.

 

 

Then you can use PUT(M,{i,j},i*j) to let the element in row i and column j be i*j.

0 Kudos
joeres
Author
Level 1
6 5 1 1
Message 6 of 13
Flag Post
HP Recommended

Hi Maké and Jan_D,

 

many thanks for your help.

Now i have a solution for my exercise  (Dimension and name of matrix variable read from stack):

\<< \-> DIM VNAME
  \<< { DIM DIM } 0 CON VNAME STO
    1 DIM FOR I
      1 DIM FOR J
        VNAME { I J } I J * PUT
      NEXT
    NEXT
    VNAME VISITB
  \>>
\>>

 

With VISITB can you call the matrix writer for the given variable.

 

Kind regards,

joeres

Tags (2)
Jan_D
Level 6
305 297 32 76
Message 7 of 13
Flag Post
HP Recommended

Well done!

I did not know VISITB.

0 Kudos
David_M
Level 6
140 139 29 60
Message 8 of 13
Flag Post
HP Recommended

That's actually very close to the solution I had in mind, especially considering the second part of your request (the random number part).  One suggestion: putting the data on the stack and building the array with ->ARRY is considerably faster:

\<<
  \-> dim vname \<<
    1 dim FOR row
      1 dim FOR col
        row col *
      NEXT
    NEXT
    dim DUP 2 \->LIST \->ARRY
    vname SWAP OVER STO
    VISITB
  \>>
\>>
0 Kudos
joeres
Author
Level 1
6 5 1 1
Message 9 of 13
Flag Post
HP Recommended

Hi David_M,

 

wow, the performance is really great. Can you explain why is you solution so fast?

 

Thanks and kind regards

joeres

0 Kudos
David_M
Level 6
140 139 29 60
Message 10 of 13
Flag Post
HP Recommended

It's actually easier to answer a slightly different question: why is the other method much slower?

 

Short answer: PUT is a complex command that has to do a lot of checking before actually storing a single value into its target location.

 

Longer answer: Besides the inherent type checking that takes place initially (list? matrix? global?), there's also index checking (does the identified index already exist?).  Basically a lot of things have to be verified and determined before PUT can actually PUT something.  Then consider that all of that overhead occurs for each and every element you are adding to the matrix (array).  You start to get an idea why it can take a while.

 

The version I proposed limits its inner loop to the simplest operation (multiplying the indices).  Since the majority of processing time for the program is in that loop structure, keeping it simple has a nice payoff in execution time.

 

When you only need to change an item or two in a pre-existing array, PUT is probably the best choice.  When building the array from scratch, loading the stack and using ->ARRY will almost always be faster.  And generally speaking, keeping inner loops as simple as possible should always be a design consideration since the code they contain can be repeated many times.

 

Hope this helps!

- David

† The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation