Post Reply 
New guy and programming problem
08-27-2017, 06:18 AM
Post: #1
New guy and programming problem
Hey guys, I'm new here. I'm an electronics engineer and I mainly work in the computer science field specifically in data analysis and mainly machinne learning. I'm a programmer in many languages (for data analysis I use Python) and I'm a fan of vintage things when things were made to last forever. I've been out hunting for a calculator for some time now since I really don't like my dad's Casio fx something (1980's long calculator with full pc style keyboard programmable in basic). When I was studying I used the HP48g+ but I lost it (stolen) and now I want something a bit smaller. I'm a believer that RPN is the only practical method for a calculator (if u r going to input large things that need reviewing u r better with a computer) and so I started looking around. After a long search, I sadly found out that I liked the HP42s over everything and so here I am sitting waiting for SwissMicros to release their tribute while I use Free42 on my phone. I watched all of Logan's videos (yes, from every calculator, not only the 42S) and just now I wrote my first program and it is to get the total resistance of 2 parallel resistors (and want to write one for 3 and 4 parallel ones and some transistor's formulas for my hobbies) and I found myself in my first problem: If I have the variables R1 and R2 already set with the right values and I call the function, it runs perfectly but if I have everything cleared and I input the variables when the function asks for them, the program doesn't run. If after that first run I call it again, it works perfectly (since the variables are already stored). Can anyone help me?

LBL "PAR2"
INPUT "R1"
1/X
INPUT "R2"
1/X
+
1/X
END


For those who don't know the formula, it is 1 / ( 1/R1 + 1/R2)

thanks in advance and also thanks for running such an awesome web
Find all posts by this user
Quote this message in a reply
08-27-2017, 03:15 PM (This post was last modified: 08-27-2017 03:40 PM by Dieter.)
Post: #2
RE: New guy and programming problem
(08-27-2017 06:18 AM)Skirmitch Wrote:  LBL "PAR2"
INPUT "R1"
1/X
INPUT "R2"
1/X
+
1/X
END

This program will not work correctly if you enter a value at the R1 resp. R2 prompt. If you do so, the previous content of that variable (the value displayed after "R1?" resp. "R2?") will be pushed to Y and the new value is in X. So this mixes up the stack contents and the calculation will go wrong. Some later calculators, e.g. the 35s, behave differently in this regard.

Anyway, you can do it this way:

Code:
01 LBL "PAR2"
02 INPUT "R1"
03 INPUT "R2"
04 RCL"R1"
05 1/X
06 RCL"R2"
07 1/X
08 +
09 1/X
10 "Rtotal="
11 AVIEW
12 END

You can insert a STO "R1" between line 09 and 10 so that the result is stored as input for the next calculation. This way you can add further resistors in parallel without having to re-enter the last result.

But you can also do it without this fancy prompting and named variables:

Code:
01 LBL "PAR"
02 1/X
03 x<>y
04 1/X
05 +
06 1/X
07 END

Or even better since it also allows zero resistances:

Code:
01 LBL "PAR"
02 RCLx ST Y
03 x<>y
04 RCL+ ST L
05 /
06 END

If you replace line 03 with RCL ST Y you can even see both the current result in X and the previous one in Y. ;-)

Both versions work for as many resistors in parallel as you like:

100 [ENTER] 150 [XEQ]"PAR" => 60
200 [R/S] => 46,15
  50 [R/S] => 24

Dieter
Find all posts by this user
Quote this message in a reply
08-27-2017, 05:12 PM
Post: #3
RE: New guy and programming problem
(08-27-2017 03:15 PM)Dieter Wrote:  Both versions work for as many resistors in parallel as you like:

100 [ENTER] 150 [XEQ]"PAR" => 60
200 [R/S] => 46,15
  50 [R/S] => 24

Dieter

For this task, no program is needed on the WP34S:

100 [ENTER] 150 [g] || => 60.
200 [g] || => 46.1538461538
50 [g] || => 24.



Problem:

What resistor should be paralleled to a 100 ohm resistor so that the equivalent resistance is 32 ohm?

On the WP34S I just do

100 +/- [ENTER] 32 [g] || => 47.0588235294

Indeed,

100 [ENTER] 47 [g] || => 31.9727891156

Is there another calculator that offers this as a built-in function?

Gerson.
Find all posts by this user
Quote this message in a reply
08-27-2017, 05:43 PM (This post was last modified: 08-27-2017 06:04 PM by Dieter.)
Post: #4
RE: New guy and programming problem
(08-27-2017 05:12 PM)Gerson W. Barbosa Wrote:  For this task, no program is needed on the WP34S:
...
What resistor should be paralleled to a 100 ohm resistor so that the equivalent resistance is 32 ohm?

On the WP34S I just do

100 +/- [ENTER] 32 [g] || => 47.0588235294

With one of the above programs you just do
–100 [ENTER] 32 [XEQ]"PAR" => 47,0588...

Sure, it's the same formula. ;-)

(08-27-2017 05:12 PM)Gerson W. Barbosa Wrote:  Is there another calculator that offers this as a built-in function?

I don't know one. But I admit I never understood why this rather special function has been implemented on the 34s and even got direct keyboard access. OK, there are a few occasions when the parallel function may be used for other mathematical applications, but IMvHO others would have made more sense. For instance functions that accurately evaluate √(1+x²) – 1, or in addition to ex–1 a general ax–1 function. Or 1–sin(x) and 1–cos(x). Or √(x²+y²). And let's not forget the useful DIVMOD function that simultaneously returns both quotient and remainder. Some of these are part of the Boost math package, so they seem to make sense for others, too. ;-)

On the other hand the || function can be programmed easily in just four steps, cf. the examples above.

Dieter
Find all posts by this user
Quote this message in a reply
08-27-2017, 05:52 PM
Post: #5
RE: New guy and programming problem
(08-27-2017 03:15 PM)Dieter Wrote:  
(08-27-2017 06:18 AM)Skirmitch Wrote:  LBL "PAR2"
INPUT "R1"
1/X
INPUT "R2"
1/X
+
1/X
END

This program will not work correctly if you enter a value at the R1 resp. R2 prompt. If you do so, the previous content of that variable (the value displayed after "R1?" resp. "R2?") will be pushed to Y and the new value is in X. So this mixes up the stack contents and the calculation will go wrong. Some later calculators, e.g. the 35s, behave differently in this regard.

Anyway, you can do it this way:

Code:
01 LBL "PAR2"
02 INPUT "R1"
03 INPUT "R2"
04 RCL"R1"
05 1/X
06 RCL"R2"
07 1/X
08 +
09 1/X
10 "Rtotal="
11 AVIEW
12 END

You can insert a STO "R1" between line 09 and 10 so that the result is stored as input for the next calculation. This way you can add further resistors in parallel without having to re-enter the last result.

But you can also do it without this fancy prompting and named variables:

Code:
01 LBL "PAR"
02 1/X
03 x<>y
04 1/X
05 +
06 1/X
07 END

Or even better since it also allows zero resistances:

Code:
01 LBL "PAR"
02 RCLx ST Y
03 x<>y
04 RCL+ ST L
05 /
06 END

If you replace line 03 with RCL ST Y you can even see both the current result in X and the previous one in Y. ;-)

Both versions work for as many resistors in parallel as you like:

100 [ENTER] 150 [XEQ]"PAR" => 60
200 [R/S] => 46,15
  50 [R/S] => 24

Dieter

Your third code not only allows zero resistances but is also more accurate, especially if there are both large and small resistances involved. Joe Horn explains the concept here.

For the 48gx and later, this can be simply expressed as:

\<< DUP \GPLIST DUP ROT / \GSLIST / \>>

for a list of two or more resistances.

John
Find all posts by this user
Quote this message in a reply
08-27-2017, 06:03 PM
Post: #6
RE: New guy and programming problem
[quote='Dieter' pid='77950' dateline='1503846914']]

Or even better since it also allows zero resistances:

Code:
01 LBL "PAR"
02 RCLx ST Y
03 x<>y
04 RCL+ ST L
05 /
06 END


Except when both are zero. No need to change your short code just because of that, though. Everybody knows 0 || 0 = 0 :-)

The WP34S has been updated because of this minor detail. But not in time for the HHC 2012 RPN Programming Contest:


http://www.hpmuseum.org/cgi-sys/cgiwrap/...ead=232750 (Messages #15 through #20).

Gerson.
Find all posts by this user
Quote this message in a reply
08-27-2017, 06:04 PM
Post: #7
RE: New guy and programming problem
Woooooooooooooo great replies!!!!! thnks a lot guys!!. Last night after reading the programming examples manual from hp (the original one) I solved the problem as follows:

01 LBL "PAR2"
02 INPUT "R1"
03 INPUT "R2"
04 RCL"R1"
05 1/X
06 RCL"R2"
07 1/X
08 +
09 1/X

but I couldn't understand why the other one was failing and now I do, thanks a lot for the info. Regarding that other calculator, I never heard of it before so I'll def check it out and thnks a LOT for the "as many resistors as u want" program, that's clearly way beyond my programming capabilities rn so it will be very very useful
Find all posts by this user
Quote this message in a reply
08-27-2017, 06:11 PM (This post was last modified: 08-27-2017 06:15 PM by Dieter.)
Post: #8
RE: New guy and programming problem
(08-27-2017 06:03 PM)Gerson W. Barbosa Wrote:  
(08-27-2017 03:15 PM)Dieter Wrote:  Or even better since it also allows zero resistances:
...
Except when both are zero. No need to change your short code just because of that, though. Everybody knows 0 || 0 = 0 :-)

Everyone knows that 1+1=2 but your calculator does it anyway. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
08-27-2017, 06:23 PM
Post: #9
RE: New guy and programming problem
(08-27-2017 06:11 PM)Dieter Wrote:  Everyone knows that 1+1=2 but your calculator does it anyway. ;-)

Depending on its mood (ok, mode), sometimes my HP-16C tells me 1 + 1 = 10 :-)

Gerson.
Find all posts by this user
Quote this message in a reply
08-27-2017, 06:28 PM (This post was last modified: 08-27-2017 06:34 PM by Dieter.)
Post: #10
RE: New guy and programming problem
(08-27-2017 05:52 PM)John Keith Wrote:  Your third code not only allows zero resistances but is also more accurate, especially if there are both large and small resistances involved.

Yes.
To be honest, this was the major reason for me to implement the formula that way. ;-)

(08-27-2017 05:52 PM)John Keith Wrote:  Joe Horn explains the concept here.

Nice to see that others are concerned about numerical accuracy as well.

Dieter
Find all posts by this user
Quote this message in a reply
08-27-2017, 07:52 PM
Post: #11
RE: New guy and programming problem
(08-27-2017 06:11 PM)Dieter Wrote:  Everyone knows that 1+1=2 but your calculator does it anyway. ;-)

Dieter

Until you buy a gaxio.




Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
08-27-2017, 09:14 PM
Post: #12
RE: New guy and programming problem
(08-27-2017 05:12 PM)Gerson W. Barbosa Wrote:  Problem:

What resistor should be paralleled to a 100 ohm resistor so that the equivalent resistance is 32 ohm?

On the WP34S I just do

100 +/- [ENTER] 32 [g] || => 47.0588235294

Indeed,

100 [ENTER] 47 [g] || => 31.9727891156

Is there another calculator that offers this as a built-in function?

Is that really any easier than 32 1/X 100 1/X - 1/X ?

http://WilsonMinesCo.com (Lots of HP-41 links at the bottom of the links page, http://wilsonminesco.com/links.html )
Visit this user's website Find all posts by this user
Quote this message in a reply
08-27-2017, 11:12 PM
Post: #13
RE: New guy and programming problem
(08-27-2017 05:43 PM)Dieter Wrote:  I don't know one. But I admit I never understood why this rather special function has been implemented on the 34s and even got direct keyboard access. OK, there are a few occasions when the parallel function may be used for other mathematical applications, but IMvHO others would have made more sense. For instance functions that accurately evaluate √(1+x²) – 1, or in addition to ex–1 a general ax–1 function. Or 1–sin(x) and 1–cos(x). Or √(x²+y²).

I seem to remember there were a couple of vocal advocates for || being easily accessible. I didn't see the need for it but apparently it is a critical feature that makes any calculator without it useless. I saw no harm and Walter was the layout person.

Yes to your other suggestions for improving accuracy, I got in what I could -- limited flash space and running out of energy justifying everything.

Apart from 1 - sin(x) which doesn't have accuracy concerns that I can see and √(x²+y²) which is present already as complex ABS.


Pauli
Find all posts by this user
Quote this message in a reply
08-28-2017, 01:44 AM
Post: #14
RE: New guy and programming problem
I'm simply astonished by the amount of replies and the quality of he comments.... It would be absolutely impossible to receive answers like this from HP. I'm investigating that community made calculator and looks awesome but it seems in ran perfectly only on the 30b and now on the new platforms it has some issues in one or two keys, damn that's bad luck Sad
Find all posts by this user
Quote this message in a reply
08-28-2017, 01:58 AM
Post: #15
RE: New guy and programming problem
(08-28-2017 01:44 AM)Skirmitch Wrote:  I'm investigating that community made calculator and looks awesome but it seems in ran perfectly only on the 30b and now on the new platforms it has some issues in one or two keys, damn that's bad luck Sad

The 34S runs fine on either the 20b or 30b hardware. As for the keys, neither have great keyboards and squishy keys are all too common.


Pauli
Find all posts by this user
Quote this message in a reply
08-28-2017, 02:25 AM
Post: #16
RE: New guy and programming problem
(08-28-2017 01:58 AM)Paul Dale Wrote:  
(08-28-2017 01:44 AM)Skirmitch Wrote:  I'm investigating that community made calculator and looks awesome but it seems in ran perfectly only on the 30b and now on the new platforms it has some issues in one or two keys, damn that's bad luck Sad

The 34S runs fine on either the 20b or 30b hardware. As for the keys, neither have great keyboards and squishy keys are all too common.


Pauli


Yeah sadly I'm after 48g+ style keys and that's a deal breaker. If I won't have that I prefer the free42 in my phone. I jusy run an ssh to my computer to use python for extremely complicated stuff.
Find all posts by this user
Quote this message in a reply
08-28-2017, 03:43 AM
Post: #17
RE: New guy and programming problem
If I had to do this often I'd write it in a program that the solver could use

Code:

LBL "RPAR"
MVAR "R1"
MVAR "R2"
MVAL "RP"
RCL "R1"
1/X
RCL "R2"
1/X
+
1/X
RCL "RP"
-
.END.
Find all posts by this user
Quote this message in a reply
08-28-2017, 05:31 AM
Post: #18
RE: New guy and programming problem
(08-28-2017 02:25 AM)Skirmitch Wrote:  Yeah sadly I'm after 48g+ style keys and that's a deal breaker.

You are underestimating the quality and feel keys can have Smile


Pauli
Find all posts by this user
Quote this message in a reply
08-28-2017, 07:14 AM
Post: #19
RE: New guy and programming problem
(08-28-2017 05:31 AM)Paul Dale Wrote:  
(08-28-2017 02:25 AM)Skirmitch Wrote:  Yeah sadly I'm after 48g+ style keys and that's a deal breaker.

You are underestimating the quality and feel keys can have Smile


Pauli


Oh, not, at all, I don't know those models so I can't judge I just know that I want keys as good or better than the ones on the HP 48g+ and without glitches. My negative opinion comes from this statement:

"Note: Because the HP 30b has been discontinued, I no longer have "perfect" units available. All 34S calculators that I am shipping now have a minor keyboard issue, where one or two of the keys takes more force to press than the others. If you are really picky it may be an issue, otherwise it is no worse than the other, less-than-perfect modern HP calculators, as this exemplifies the poor quality control of HP's current offerings."

Which is found on this page: http://commerce.hpcalc.org/34s.php

That's what discouraged me and makes me keep on waiting for SwissMicros to release a 42S tribute. Again, I would LOVE to go back to the 48g+ but its just too big
Find all posts by this user
Quote this message in a reply
08-28-2017, 07:28 AM
Post: #20
RE: New guy and programming problem
I think you misunderstood. The 30b's keys aren't great, I'm not contesting that. I'm also aware of Eric's comments. I meant the earlier HP calculators that feel, to me, much better than the later ones. Get a classic from the 1970's and see how good keys can be.


Pauli
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: