New guy and programming problem
08-27-2017, 05:52 PM
Post: #5
 John Keith Senior Member Posts: 837 Joined: Dec 2013
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
 « Next Oldest | Next Newest »

 Messages In This Thread New guy and programming problem - Skirmitch - 08-27-2017, 06:18 AM RE: New guy and programming problem - Dieter - 08-27-2017, 03:15 PM RE: New guy and programming problem - Gerson W. Barbosa - 08-27-2017, 05:12 PM RE: New guy and programming problem - Dieter - 08-27-2017, 05:43 PM RE: New guy and programming problem - Paul Dale - 08-27-2017, 11:12 PM RE: New guy and programming problem - Dieter - 08-28-2017, 06:13 PM RE: New guy and programming problem - Paul Dale - 08-29-2017, 04:22 AM RE: New guy and programming problem - Garth Wilson - 08-27-2017, 09:14 PM RE: New guy and programming problem - Vtile - 09-01-2018, 07:28 PM RE: New guy and programming problem - John Keith - 08-27-2017 05:52 PM RE: New guy and programming problem - Dieter - 08-27-2017, 06:28 PM RE: New guy and programming problem - Gerson W. Barbosa - 08-27-2017, 06:03 PM RE: New guy and programming problem - Dieter - 08-27-2017, 06:11 PM RE: New guy and programming problem - Gerson W. Barbosa - 08-27-2017, 06:23 PM RE: New guy and programming problem - pier4r - 08-27-2017, 07:52 PM RE: New guy and programming problem - Jlouis - 08-28-2017, 10:55 AM RE: New guy and programming problem - Skirmitch - 08-27-2017, 06:04 PM RE: New guy and programming problem - Skirmitch - 08-28-2017, 01:44 AM RE: New guy and programming problem - Paul Dale - 08-28-2017, 01:58 AM RE: New guy and programming problem - Skirmitch - 08-28-2017, 02:25 AM RE: New guy and programming problem - Paul Dale - 08-28-2017, 05:31 AM RE: New guy and programming problem - Skirmitch - 08-28-2017, 07:14 AM RE: New guy and programming problem - ndzied1 - 08-28-2017, 03:43 AM RE: New guy and programming problem - Paul Dale - 08-28-2017, 07:28 AM RE: New guy and programming problem - Logan - 08-28-2017, 02:20 PM RE: New guy and programming problem - Skirmitch - 08-28-2017, 06:11 PM RE: New guy and programming problem - Logan - 08-28-2017, 06:13 PM RE: New guy and programming problem - Thomas Klemm - 09-01-2018, 12:23 PM RE: New guy and programming problem - Albert Chan - 09-01-2018, 02:16 PM RE: New guy and programming problem - Albert Chan - 09-02-2018, 06:14 PM RE: New guy and programming problem - Albert Chan - 09-02-2018, 09:21 PM RE: New guy and programming problem - sasa - 09-01-2018, 03:18 PM RE: New guy and programming problem - Albert Chan - 09-01-2018, 05:20 PM RE: New guy and programming problem - sasa - 09-01-2018, 05:33 PM RE: New guy and programming problem - Thomas Klemm - 09-01-2018, 04:28 PM RE: New guy and programming problem - Thomas Klemm - 09-02-2018, 07:33 PM RE: New guy and programming problem - Thomas Klemm - 09-02-2018, 09:33 PM RE: New guy and programming problem - Vtile - 09-02-2018, 09:40 PM RE: New guy and programming problem - Albert Chan - 09-03-2018, 10:32 PM

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