cancel
Isai5 Student
Student
1 0 0 0
Message 1 of 2
307
Flag Post
HP Recommended

Create matrix, basics

HP 50g
Unknown

I want to create a matrix of 6x6 with their elements dependent on initial values. I am new programming in HP 50g.

 

I wrote this:

 

«"KLOCAL" {":E:

:B:

:H:

:L:"{1 0} V} INPUT OBJ -> E B H L

« '12*E*B*H/L' -> a

'6*E*B*H/L' -> b»

«{6 6} 0 KLOCAL STO»

«KLOCAL {1 1} a PUT

KLOCAL {1 2} b PUT» % and so on

»

 

Something is wrong, I couldn't solve it. Please help me, I am a new user of programming in HP 50g.

Tags (1)
1 REPLY 1
Grad Student
Grad Student
124 118 22 45
Message 2 of 2
210
Flag Post
HP Recommended

Create matrix, basics

Hi Isai5 -

 

The creation of local variables in RPL code uses a specific structure:

 

obj1

...

objN

name1...nameN

« code »

 

Note how a code object immediately follows the variable name(s). The local variables are available to all code within the identified code block, including any nested local variable structures. This may or may not be important to you, depending on how the matrix elements need to be constructed.

 

There are several syntactical issues with your code, and it's not entirely clear what some of it is trying to do. The following is based on my guesses as to what you meant to do with your sample.

 

 

 

« "KLOCAL"
{ ":E:
:B:
:H:
:L:"
{ 1 0 } V } INPUT OBJ→
→ E B H L
« ...

 

I believe the first part of your program is doing what you likely intended. It prompts for values to assign to locals E, B, H, and L. All of the code in the following block will have access to these variables, and they will cease to exist after the code finishes.

 

 

« '12*E*B*H/L' → a
'6*E*B*H/L' → b »

 

My interpretation of what you intended here is to store either symbolic formulas or possibly computed values into local variables a and b. Either way, the code as written would create a syntax error for the RPL compiler. Note the above description of the needed structure for local variable declarations. For now, I'm going to assume that you meant to create computed values for a and b that are based on E, B, H, and L, and then store those values in locals a and b for subsequent use. If that's the case, the following should work for this:

 

'12*E*B*H/L' →NUM
'6*E*B*H/L' →NUM
→ a b
« ...

 

 

 

« { 6 6 } 0 KLOCAL STO »

 

This may actually compile successfully, but I doubt it would do what you have in mind. It's not entirely clear what your goal is here, but I'm going to make a guess and suggest that you are trying to create a 6x6 matrix with 0s for all elements, then storing it into a global variable named KLOCAL. If that's the case, here's one way to accomplish that:

 

 

{ 6 6 } 0 CON 'KLOCAL' STO

 

Notes

  • There's no need to encapsulate this section into its own code block with « ». Doing so would simply place the code block on the stack without executing it.
  • CON creates a matrix (or array) based on the provided parameters, then leaves it on the stack.
  • 'KLOCAL' leaves the variable name 'KLOCAL' on the stack without recalling its contents. The single quotes are important here, as you are specifying the name of the variable instead of recalling its contents onto the stack.

 

 

« KLOCAL { 1 1 } a PUT
KLOCAL { 1 2 } b PUT »

 

I believe you are intending to store the values for a and b into positions { 1 1 } and { 1 2 } of global variable KLOCAL. This code won't do that, however. First, the brackets surrounding the code means that the code block will simply be placed on the stack instead of being executed. So the brackets shouldn't be included. Even if you had left off the brackets, the lack of single quotes around KLOCAL means that the contents of KLOCAL are recalled to the stack in both cases (instead of PUTting the values into the KLOCAL variable). So executing this code would simply leave two 6x6 copies of KLOCAL on the stack, each with 1 value substituted as indicated.

 

Here's my interpretation of what you intended:

 

'KLOCAL' { 1 1 } a PUT
'KLOCAL' { 1 2 } b PUT

 

 

Combining the above into a single (but still abbreviated) code segment would provide the following:

 

«
   "KLOCAL"
   { ":E:
:B:
:H:
:L:"
   { 1 0 } V } INPUT OBJ→
   → E B H L
   «
      '12*E*B*H/L' →NUM
      '6*E*B*H/L' →NUM
      ...
      → a b ...
      «
         { 6 6 } 0 CON 'KLOCAL' STO
         'KLOCAL' { 1 1 } a PUT
         'KLOCAL' { 1 2 } b PUT
         ...
      »
   »
»

 

 

It's entirely possible that I have misinterpreted what you are trying to accomplish here, so please keep that in mind. In either event, I hope this helps out in some way! It's also possible to use entirely different means to create the matrix you have in mind. In particular, putting all 36 of the elements on the stack and then executing { 6 6 } →ARRY would probably take less code and run faster. But the above code was written to be as close as possible to your original version.

Reply
0 Kudos
† 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