Post Reply 
50g multiple output
12-03-2021, 03:43 PM
Post: #1
50g multiple output
Hi all.
I'm new in this forum and quite a new HP calculator user.
When I discovered HP world (at university) I was fascinating on it, but during ’90 years I had not a lot of money to change calculator and HP was really expensive. My first programmable calculator (in fact) was an old CASIO FX850-P, I still have it since 1989 and still work, this calculator had a BASIC programming interface, really simple.
During lockdown I bought a 50g and I tried to start programming it and I found really difficult. I also have a HP 35s bought to keep it in office, with this calculator I understood RPN mode, I like it and I started to program this calculator, I found it really simple and intuitive, so I decided to move to an upgrade, the 50g.
I’m sure that my difficult are due to difference between a basic like language (typical of Casio calculator) and User RPL, but I found this language so strange that it’s extremely difficult for me find some solution.

One of my tipical problem is this:
I’m approaching with a simple financial formula to calculate a periodical amount of a loan, formula is simple: ( I can solve it with a simple formula in the equation editor, but I would solve it with a program to made some practice.
I had no problem to input initial data: amount of a loan, interest rate, number or yearly period (12 in this case), number of years.
I need to calculate:
  • montly amount;
  • total amount;
  • interest.
Formula I use (is not important now), is R=C+((t/100/12)/(1-(1+t/100/12)^(-A*12)), where:
  • R: montly amount;
  • t: annual interest rate;
  • A: number of years.
My problem is to calculate the three quantities above and show them in the display. I can only calculate one (montly amount, or total amount, or interest), but not the other because I can’t recall intermediate calculation and display it correctly.
I'm locked in this kind of problem, I'm sure that is stupid, but I've no idea to unlok my mind now.
Thanks in advance for any help.
Find all posts by this user
Quote this message in a reply
12-03-2021, 09:44 PM
Post: #2
RE: 50g multiple output
I do not have my 50g with me here at work, but there is already a finacial module in the calc that works. Don't remember where it is but it should be in a menu by one of the shift keys and one of the number keys. Look for "financial" on your keypad.

Esben
15C CE, 28s, 35s, 49G+, 50G, Prime G2 HW D, SwissMicros DM32, DM42, DM42n, WP43 Pilot
Elektronika MK-52 & MK-61
Find all posts by this user
Quote this message in a reply
12-03-2021, 10:42 PM (This post was last modified: 12-04-2021 04:46 AM by Joe Horn.)
Post: #3
RE: 50g multiple output
(12-03-2021 09:44 PM)DA74254 Wrote:  I do not have my 50g with me here at work, but there is already a finacial module in the calc that works. Don't remember where it is but it should be in a menu by one of the shift keys and one of the number keys. Look for "financial" on your keypad.

Left-shift 9 launches the built-in Finance input form & solver. If you prefer the soft-menu finance app from the HP 48, it's available in the 50g by typing 80 MENU. Press NXT if you need to change BEGIN/END mode or the number of payments per year.

EDIT: Oops, I forgot about the 50g's built-in key path to the 48-style finance solver: Press and hold down Right-shift, then press 7 and release both. Then press the TVM menu key, then the SOLVR menu key.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
12-04-2021, 08:13 AM
Post: #4
RE: 50g multiple output
Hi .
Thnks but program I'm try to made is only an example. I saw that there is a lot of financial functions.
Then I forget to write my simple code:
<<"insert C t a"
{":C:
:t:
:A:"
{1 0 } V} INPUT OBJ-> -> C t A 'C*(t/100/12/(1-(1+t/100/12)^(-A*12)))' -> NUM "R" -> TAG>>

If I try to calculate also total amount due (with formula M=R*A*12) nothing works.

I modified program like this:

<<"insert C t a"
{":C:
:t:
:A:"
{1 0 } V} INPUT OBJ-> -> C t A 'C*(t/100/12/(1-(1+t/100/12)^(-A*12)))' -> NUM "R" -> TAG 'R*A*12' -> NUM "M" -> TAG>>
but ressult it's wrong.
I'm sure is a syntax problem but I don' understand where.
Can someone help me?
Thanks in advance.
Find all posts by this user
Quote this message in a reply
12-05-2021, 02:35 PM (This post was last modified: 12-05-2021 03:20 PM by nlj.)
Post: #5
RE: 50g multiple output
(12-04-2021 08:13 AM)oierpa Wrote:  If I try to calculate also total amount due (with formula M=R*A*12) nothing works.
...
<<"insert C t a"
{":C:
:t:
:A:"
{1 0 } V} INPUT OBJ-> -> C t A 'C*(t/100/12/(1-(1+t/100/12)^(-A*12)))' -> NUM "R" -> TAG 'R*A*12' -> NUM "M" -> TAG>>
but ressult it's wrong.
I'm sure is a syntax problem but I don' understand where.
Can someone help me?

Two apparent errors that immediately jump out from the code above are these:

1) The -> command creates local variables whose scope is limited to the following algebraic or program object. So by the time you get to the 'R*A*12' algebraic your local variables are gone and the A here refers to a global variable A.

2) You haven't assigned a value to R in your program. Presumably you intend R to to refer to the value you put on the stack that you labelled "R" with the TAG command, but the calculator doesn't know what you intend. (And again in 'R*A*12', R refers to a global variable R.)

You can fix Problem 1 by wrapping everything in a program object (with << and >>) from just before your first algebraic to the the end of the program.

I hope this helps.

N.

[Edited with slightly better English.]
Find all posts by this user
Quote this message in a reply
12-05-2021, 06:23 PM
Post: #6
RE: 50g multiple output
Hi Nlj.
Thanks a lot for your help.
Can you suggest me some readings, article, manual or website that explain a little more how variables are used inside program?
I would finish this simple program by myself (I've several other program to made), I understood that syntax I used is really wrong, I assumed that calculator has same variables handlig of other environment (like basic that is more familiar for me).
Thanks in advance.
Find all posts by this user
Quote this message in a reply
12-06-2021, 12:39 PM
Post: #7
RE: 50g multiple output
(12-05-2021 06:23 PM)oierpa Wrote:  Can you suggest me some readings, article, manual or website that explain a little more how variables are used inside program?

One very good source is https://literature.hpcalc.org/. Nearly every HP manual is available there, as well as many third party manuals. Even better is the Museum thumb drive which has even more manuals and literature in a convenient form.

Specifically, the Programming section in the HP 50g advanced user's reference has the info you are looking for. The 50g users manual is somewhat infuriating to use because every example has both RPN and algebraic versions. The HP48G user's manual is more readable but obviously doesn't cover features of newer calculators. William Wickes' HP48 Insights (GX Version) is also a valuable reference. It is on the thumb drive but not on hpcalc.org.

RPL is an unusual programming language, especially compared to BASIC which is used on many other scientific calculators. Some people love it, others hate it or just never get it. RPL is based primarily on LISP and FORTH so familiarity with those languages is helpful. The local variable structure that you are having trouble with is similar to lambda expressions as you would find in LISP, Python or Haskell.
Find all posts by this user
Quote this message in a reply
12-06-2021, 02:36 PM
Post: #8
RE: 50g multiple output
Hi all.
I made some test and I understood something more.
Here there is my program list:
Code:
<<"Ins C t A n" {
    ":C:
     :t:
     :A:
     :n:" {1 0} V} INPUT OBJ-> -> C t A n
     << t 100 / 'n' RCL / DUP 1+ 'n' RCL 
     'A' RCL * NEG ^ NEG 1 + / 'C' RCL * 
     'R' STO>>
      'n' RCL 'A' RCL *
      'R' RCL * "M" -> TAG 
      ->STR "
      " ->STR + 'R' RCL "R" -> TAG 
      ->STR +
      MSGBOX 'R' PURGE
       >>
With this syntax I can calculate and display 2 different result (obtained with the same input data). I used RPN and not Algebraic because when I try use this notation variables are changing.
Thanks to all that read and can suggest me something to do better programs.
Find all posts by this user
Quote this message in a reply
12-06-2021, 05:59 PM
Post: #9
RE: 50g multiple output
Hi oierpa,

(12-05-2021 06:23 PM)oierpa Wrote:  ... Can you suggest me some readings, article, manual or website that explain a little more how variables are used inside program? ...

My answer to this was going to be very similar to the one from John Keith above, although his is more detailed. Smile

If you want to limit the amount of reading you need to do initially, I would say that the "Chapter 1: RPL Programming" and possibly "Chapter 2: Programming Examples" in the "HP 50g / 49g+ / 48gii Graphing Calculator Advanced User's Reference Manual" are essential reading.

I agree with John that the "HP 50g Graphing Calculator User's Manual" [and also the "HP 50g Graphing Calculator User's Guide"] are somewhat infuriating and that going back to a manual to a less evolved calculator in the line can be better. But rather than the manuals for the 48G, I would suggest that the manuals for the 48SX cannot be beaten for clarity and simplicity even though the calculator is less similar to the 50g.

(12-05-2021 06:23 PM)oierpa Wrote:  ... I understood that syntax I used is really wrong. ...

Not "really" wrong. I'd say you are more than 90% of the way there. Smile

(12-06-2021 02:36 PM)oierpa Wrote:  Hi all.
I made some test and I understood something more.
Here there is my program list:
Code:
<<"Ins C t A n" {
    ":C:
     :t:
     :A:
     :n:" {1 0} V} INPUT OBJ-> -> C t A n
     << t 100 / 'n' RCL / DUP 1+ 'n' RCL 
     'A' RCL * NEG ^ NEG 1 + / 'C' RCL * 
     'R' STO>>
      'n' RCL 'A' RCL *
      'R' RCL * "M" -> TAG 
      ->STR "
      " ->STR + 'R' RCL "R" -> TAG 
      ->STR +
      MSGBOX 'R' PURGE
       >>
With this syntax I can calculate and display 2 different result (obtained with the same input data). I used RPN and not Algebraic because when I try use this notation variables are changing.
Thanks to all that read and can suggest me something to do better programs.

* You don't need all those RCL statements. Instead of 'n' RCL just use n. ('n' (with quotes) evaluates to the name of the object and n (without quotes) evaluates to the value of the object.)

* You can still use your algebraic objects if you like. In a formula an algebraic can sometimes be more readable. Just remember that the scope of local variables is the following algebraic or program object so if you want the scope of you local variables to extend beyond one algebraic then you need an enclosing program object. Along these lines:

[NOTE: The calculator sadly does not support comments in programs, but I have sprinkled comments here introduced by semicolon characters.]

Code:
<<
; This section is usually used to set up the stack so that the local variables can be assigned from it.
-> a b c <<
    ; Your local variables a, b, and c are defined here.
    'some-algebraic'         ; Your local variables are still defined inside your algebraic.
    ; And they're still defined here.
    'another-algebraic'      ; And they're defined inside this algebraic too.
    ' And they're still defined here.
>> ; End of scope of local variables a, b, and c.
>> ; End of program

* You can avoid having 'R' being a global variable (which might overwrite an existing variable 'R' that you have outside your program) by introducing a new (inner) local variable scope for 'R'.

Code:
<<
; Get C, t, A, and n on the stack by whatever means (e.g. by your INPUT OBJ-> approach).
-> C t A n <<
    ; Code calculating R, using an algebraic or otherwise.
    -> R <<
        ; Code using C, t, A, n, and R goes here.
    >> End of scope of local variable R.
>> ; End of scope of local variables C, t, A, and n.
>> ; End of program

Or more simply, put a dummy value for R on the stack (such as 0) and create R in your initial set of local variables,

Code:
<<
; Get C, t, A, and n on the stack by whatever means (e.g. by your INPUT OBJ-> approach).
0                              ; Dummy value for R
-> C t A n R <<
    ; Code calculating R, using an algebraic or otherwise.
    'R' STO                    ; Replace value of the local variable R
    ; Code using C, t, A, n, and R.
>>  ; End of scope of local variables C, t, A, n, and R.
>>  ; End of program

N.
Find all posts by this user
Quote this message in a reply
12-10-2021, 06:53 PM
Post: #10
RE: 50g multiple output
Hi Nlj.
Excuse me if I reply only now, wednesday was national holiday here (Italy) and when I come back to work I had a lot of things to do.

First of all, thank you so much, in few words I understood more than reading manual, I agree with you, sometimes is hard to understand. I think that my biggest problem is entering understanding logic of User RPL.

Anyway I make few test and of course it works.
Now last running version is:
Code:
<<"Ins C t A n" {
    ":C:
     :t:
     :A:
     :n:" {1 0} V} INPUT OBJ-> -> C t A n
     << t 100 / n / DUP 1+ n  
     A * NEG ^ NEG 1 + / C * 
     'R' STO>>
      n A *
      R * "M" -> TAG 
      ->STR "
      " ->STR + 'R' RCL "R" -> TAG 
      ->STR +
      MSGBOX 'R' PURGE
       >>
This work fine, so I tried some new versions using your suggestions.
Version with algebraic formula:
Code:

<<"Ins C t A n" {
    ":C:
     :t:
     :A:
     :n:" {1 0} V} INPUT OBJ-> -> C t A n
     << C t A n 'C* (t/100/n)/(1-(1+t/100/n)^(-n*a))' EVAL
     'R' STO 'R*n*A' EVAL >> 'M' RCL "M" -> TAG 
     -> STR "
" -> STR + 'R' RCL "R" ->TAG
-> STR +
      MSGBOX 'R' PURGE 'M' PURGE
       >>
Calculation time over a minute and an error occurred (insufficient memory)

[/php]
Find all posts by this user
Quote this message in a reply
12-11-2021, 02:18 AM (This post was last modified: 12-11-2021 04:23 AM by nlj.)
Post: #11
RE: 50g multiple output
Hi oierpa,

(12-10-2021 06:53 PM)oierpa Wrote:  I think that my biggest problem is entering understanding logic of User RPL.

I feel that you are maybe making it more complicated for yourself than it need be. With the exception of a few control flow constructs almost everything in UserRPL is exactly the same as the RPN you use when using the calculator interactively*.

The only thing you really need to wrap your mind around is the simple idea that commands take zero or more arguments off the bottom of the stack and return zero or more results there.

[* If you normally use the calculator in algebraic mode, I suggest you switch it RPN mode at least to get yourself in the right mindset for programming the calculator.]

(12-10-2021 06:53 PM)oierpa Wrote:  Anyway I make few test and of course it works.
Now last running version is:
Code:
<<"Ins C t A n" {
    ":C:
     :t:
     :A:
     :n:" {1 0} V} INPUT OBJ-> -> C t A n
     << t 100 / n / DUP 1+ n  
     A * NEG ^ NEG 1 + / C * 
     'R' STO>>
      n A *
      R * "M" -> TAG 
      ->STR "
      " ->STR + 'R' RCL "R" -> TAG 
      ->STR +
      MSGBOX 'R' PURGE
       >>
This work fine, so I tried some new versions using your suggestions.

I don't think that is actually working the way you intend because the `n A *' expression is not using your local variables n and A but whatever values you happen to have stored in them globally.

(12-10-2021 06:53 PM)oierpa Wrote:  Version with algebraic formula:
Code:

<<"Ins C t A n" {
    ":C:
     :t:
     :A:
     :n:" {1 0} V} INPUT OBJ-> -> C t A n
     << C t A n 'C* (t/100/n)/(1-(1+t/100/n)^(-n*a))' EVAL
     'R' STO 'R*n*A' EVAL >> 'M' RCL "M" -> TAG 
     -> STR "
" -> STR + 'R' RCL "R" ->TAG
-> STR +
      MSGBOX 'R' PURGE 'M' PURGE
       >>
Calculation time over a minute and an error occurred (insufficient memory)

Ah, now you have gotten in quite a tangle!

One thing that jumps out at me is that you haven't defined the lower case `a' in your long algebraic so that will be accessing an arbitrary global variable if you have one defined -- and if you haven't you're asking the CAS to evaluate an expression with an unknown.

To get back on track I suggest you re-read Chapter 1 on the Advanced User's Reference Manual slowly, and try little bits of your program interactively.

Also consider this simpler code which expects to get values for C, t, A and n off the stack and returns R and M to the stack (appropriately tagged). [To avoid for now your long algebraic expression, in this example R is the sum of C, t, A, and n.]

Code:

<< 0 0 -> C t A n R M
    << 'C + t + A + n' ->NUM 'R' STO
        'R * n * A' ->NUM 'M' STO 
        R "R" ->TAG
        M "M" ->TAG
    >>
>>

I hope this helps a bit!

[Edit: Replacing EVAL with ->NUM, otherwise the calculator needs to be in Numeric Results Mode (unless an exact rational result is desired, but calculating that here is very slow).]
Find all posts by this user
Quote this message in a reply
12-11-2021, 02:45 PM
Post: #12
RE: 50g multiple output
You're getting some great advice here from multiple sources. I'll add my take on a couple of specific issues.

nlj has hinted at something in one of his responses that I'd like to emphasize: everything in RPL is case-sensitive. So variable 'a' is not the same variable as 'A' (globally or locally). I suspect you probably already know that, but I just wanted to emphasize it because it can definitely make bug-finding more difficult if you've mixed the case of variable names in different parts of the program.

The User RPL concept of local variables (and the mechanics of using them) takes a little time to understand. The syntax used to define them isn't as "RPN-ish" as many would like, but I suspect was chosen in an effort to improve readability more than to fit into the traditional RPN "operand(s) first then operator" model. Just keep in mind that there are 4 distinct parts to any UserRPL local variable context:

1: objects on the stack that define the initial values of the named locals
2: the "→" operator
3: a sequence of local variable names
4: a single object that will be executed/evaluated using the named locals

That single object in item 4 above has to be one of two things: a program (enclosed in brackets « »), or an algebraic (enclosed in tic marks ' ').

The local variable names listed in item 3 above only exist for that last object. Anything following that object in your program won't ever know that they even existed, and will treat any references to those names as global variables instead. So the context of the locals both begins and ends within that single object defined in part 4.

Consider some examples. In this situation, I have created 3 global variables (A B C) and stored the values (4 5 6) into them. Then each of the following programs is executed:
Code:
o1
«
   1 2 3
    →
   A B C
   « A B C * + »
»

o2
«
   1 2 3
   →
   A B C
   'A+B*C'
»

o3
«
   1 2 3
   →
   A B C
   « A B C * + »

   « A B C * + » →NUM
»

o4
«
   1 2 3
   →
   A B C
   'A+B*C'

   'A+B*C' →NUM
»

o1 result: 7. Note that the local variable context supersedes the global variables which are already defined.

o2 result: 7. Same result as o1, same reasons.

o3 result: 7 34. Note that the exact same source code has two very different results. The local variables went out of context after the first sub-program was executed, so the same variable names in the following statement (which looks the same, but actually isn't) now refer to the previously defined global variables instead of the locals.

o4 result: 7 34. Same result as o3, same reasons.

The use of locals in RPL programs definitely has a learning curve, but the advantages in program clarity and the reduction of "stackrobatics" they afford is very real. You've got a good start on this, keep it up!
Find all posts by this user
Quote this message in a reply
01-10-2022, 11:45 AM
Post: #13
RE: 50g multiple output
Hi all.
First of all I would wish you happy new year to everybody.
I apologize for my long absence, I had some trip for work just before Christmas, then holiday and then Covid ...

The explanations of Nlj and DavidM were more useful than the manuals.
Of course I remember that variable name are case sensitive, I just written the wrong variable name "a" instead of "A", but in my calculator it was right.

I'm sure the RPL language is very solid, otherwise it wouldn't be as widespread. I just have to get into the operating logic and it is obviously my problem.

But in program o3 and o4 of DavidM I've some errors during execution (in o4 I've "-> NUM error" and in o3 "* ERROR: undefined name").

I just typed same program.
Find all posts by this user
Quote this message in a reply
01-10-2022, 12:16 PM
Post: #14
RE: 50g multiple output
(01-10-2022 11:45 AM)oierpa Wrote:  But in program o3 and o4 of DavidM I've some errors during execution (in o4 I've "-> NUM error" and in o3 "* ERROR: undefined name").

I just typed same program.

Just a guess: did you first create the global variables A, B, and C before executing the programs? See the note at the beginning of the code listings: In this situation, I have created 3 global variables (A B C) and stored the values (4 5 6) into them. Then each of the following programs is executed...

Part of what I was trying to convey here is what happens when you already have global variables defined when running code with locals using the same names.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 4 Guest(s)