cancel
Showing results for
Did you mean:
Level 1
4 3 1 0
Message 1 of 5
2,842
Flag Post

Solved!

# HP Prime: PROGRAM TO MAKE MATRICE FROM CALCULATOR's STACK (NOT WORKING!?)

HP Recommended
HP Prime

Hello!

I attend  university for electrical engineering and therefore I am considering buying myself a good calculator for my needs:

- programmable with enought memory

- graphing

I only recently discovered about HP's incredible calculators (e.g. HP 50g), that are capable of RPN notation and therefore doing calculations very quick and efficient. I really hate the new calculators that advertise "easy and quick"  input using graphical symbols and cursor to select location of input!!! This is very time consuming and is making me insane, especially when dealing with long and "complex" calculations.

As I am not able to source any new HP 50g, I looked at its "successor": HP Prime. But unfortunately it has many flaws in RPN notation and also in some functions. But I am prepared to make a compromise, especially if I can write programs to replace some crucial missing functions from HP 50G.

BUT, when I started looking into writing my own functions I quickly discovered the lack of input/output handling functions and even some strange/unexplainable behaviors.

I have written a program:

```EXPORT array()
BEGIN
LOCAL a,b,i,j;
a:=Ans(1);
IF length(a)==1
THEN
b:=MAKELIST(Ans(X),X,a+1,2,-1);
ELSE
i:=a(1);
j:=a(2);
b:=MAKEMAT( Ans(i+j+2-J-(I-1)*j),i,j);
END;

return (b);```

This program takes the last argument("a") from stack for list/matrice size.

If the argument "a" is a number (1 element list), it creates a list of last "a" arguments from the stack. ->WORKING

Else, it creates a matrice with specified rows and columns. -> NOT WORKING

Now when I tested the code without I or J arguments in MAKEMAT function, it was working OK. It was working also, if I used really simple expression: e.g. I+J-1 or i+j-J+2 (only column scanning).

(The top (1:) expression in stack is return value after running array())

LIST OK:

MATRICE not OK:

MATRICES OK, if running only Ans(i+j-J+2):

MATRICE OK, if running really simple function Ans(I+J-1):

Why these anomalies!? I was really eager to buy HP Prime, but after all these issues and no true control over calculator's stack for impressive programs 😞

HP 50g has built in functions for such conversions, but newer HP Prime doesn't.

All the best,

Ziga

Tags (1)
4 REPLIES 4
Level 6
252 251 42 77
Message 2 of 5
Flag Post
HP Recommended

Hello,

Try the folllowing program which seems to work.

EXPORT array()
BEGIN
LOCAL a,b,i,j;
a:=Ans(1);
IF size(a)==1
THEN
b:=MAKELIST(Ans(X),X,a(1)+1,2,-1);
ELSE
i:=a(1);
j:=a(2);
b:=MAKEMAT( Ans(i+j+3-J-(I-1)*j),i,j);
END;
return b;
end;

Cyrille

I am an HP Employee
Level 1
4 3 1 0
Message 3 of 5
Flag Post
HP Recommended

Your code has even some accessing out of stack!

I have tried the code just to test, what the calculator shows when such things happen:

```6: 0
5: 11
4: 22
3: 33
2: 44
1: {2,3}```

If I explain my accessing code, it does the following:

` i+j+2-J  -> accesses the "first" element in a column -> 2+3+2-1=6-(I-1)*j  -> goes through columns  -> -(1-1)*3= 0                                   -> -(2-1)*3=-3`

After writting this explanation (even after I reviewed it a couple times), I have found a crucial mistake in accessing the first element: i+j+2-J. As matrices have "rectangular shape", they cannot have prime number for its number of elements (i+j), instead the number of all elements in matrices is calculated by (i*j).

This way my code wanted to input a list into matrice and therefore strangely assigning only list to matrice b.

The size() and length() seems to work the same.

So the correct/working code is:

```EXPORT array()
BEGIN
LOCAL a,b,i,j;
a:=Ans(1);
IF size(a)==1
THEN
b:=MAKELIST(Ans(X),X,a+1,2,-1);
ELSE
i:=a(1);
j:=a(2);
b:=MAKEMAT(Ans(i*j+2-J-(I-1)*j),i,j);
END;

return (b);```

For this mistake I appologize, as I was criticising HP because of my mistake.

Unfortunately I have still some doubts about HP Prime being capable of having such powerful RPN as older HP calculators. It surely has faster processor and more memory and "Advanced RPN" that has 128-levels (max number of elements on stack), but I seem to have some issues with software, when I tried to use stack like on old HP RPN calculators. As some said this is clearly more aimed at "students", who do not like to study the impressive RPN notation (so non enthusiasts 😞 ). I have read that the firmware could be modified, so I would be able to customise/add some functions on my own, but I do not think I am that enthusiastic, especially as I have never tried any such modifications (only programming microchips in assembly and C).

Another strange thing that I have encountered is the Esc key behaviour. If I write a number/command and click Esc key, it only erases the command, but the cursors stays on command line!? Then I have to click Esc another time to exit command line. What is the point of such functionality? When I enter any number/command in Home mode it automaticaly starts to write in command line, will the next "improvement" be: in order to write any command you need to select command line and then write commands/numbers?

I really hope that there is going to happen more development for HP Prime for enthusiasts: e.g. enabling more control over stack, especially in programs (deleting stack elements, switching last elements...). Is it possible to write advanced graphical programs for HP Prime: e.g. moving objects, "games"? The processor is probably more than capable of running such applications (400MHz), only the efficiency of programming language HP PPL is then in question.

Ohh, why am I unable to post with text that is in different font and has background!?

`Your post has been changed because invalid HTML was found in the message body.The invalid HTML has been removed.Please review the message and submit the message when you are satisfied.`

Thank you for help,
Ziga

Tags (1)
Level 6
252 251 42 77
Message 4 of 5
Flag Post
HP Recommended

Hello,

HP Prime is fundamentally an Algebraic machine (while the 50 was fundamentally an RPL one).

This makes a big difference, and there is no doubt that the RPN mode in the Prime is not as advanced as the 50g one.

Prime is however much more capable than the 50g (at least at a user language level). But for someone comming from the 50g, it can be a frustrating step as a lot of the fundamentals have changed.

I do come from the 48 world, and I too have had to make the transition. However, there is something that I know. When I need to do a calculation, I pick up my prime, not my 48/49/50.

HPPL is definitely a very powerfull language and you can do a lot of graphical manipulations with it.

Where it lakes is in the number of available graphics (G0-G9, which is a carry over from the HP38G). but you can still do prety much anything you want with it. And it is fast!

Cyrille

I am an HP Employee
Level 1
4 3 1 0
Message 5 of 5
Flag Post
HP Recommended

And to sum up the program functionality:

Make a list from last A written numbers (A being the 1: command):

Make a matrice using A={i,j} scheme (A being list in 1: command):

Function array():

```EXPORT array()
BEGIN
LOCAL a,b,i,j;
a:=Ans(1);
IF size(a)==1
THEN
b:=MAKELIST(Ans(X),X,a+1,2,-1);
ELSE
i:=a(1);
j:=a(2);
b:=MAKEMAT(Ans(i*j-J+2-(I-1)*j),i,j);
END;
return (b);END;```

Tags (1)
† 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