Post Reply 
(10C or 25C) Distance Speed Time
05-13-2024, 10:43 AM (This post was last modified: 05-19-2024 10:10 AM by Gamo.)
Post: #1
(10C or 25C) Distance Speed Time
Program to find Distance, Speed or Time

When too lazy to remember all there formular
this little program will do.

Use Store Register 1, 2 and 3

R1 Distance
R2 Speed
R3 Time

Input 0 for one of the three unknow

[R/S] Answer from your selected unknown

Usage Example at this link:

https://www.hpmuseum.org/forum/thread-21720.html

Program:
Quote:01 RCL 1 // Unknown Distance?
02 X=0
03 GTO 10
04 RCL 2 // Unknown Speed?
05 X=0
06 GTO 10
07 RCL 3 // Unknown Time?
08 X=0
09 GTO 22
10 RCL 3 // Known Time then convert to decimal degree
11 →H
12 RCL 2 // Test if Speed is unknown then go to line 17
13 X=0
14 GTO 17
15 x // Calculate Distance = Speed x Time
16 GTO 00
17 X<>Y
18 RCL 1
19 X<>Y
20 ÷ // Calculate Speed = Distance ÷ Time
21 GTO 00
22 R↓
23 ÷
24 →H.MS // Calculate Time = Distance ÷ Speed

Gamo 5/2024
Find all posts by this user
Quote this message in a reply
05-13-2024, 10:20 PM (This post was last modified: 05-13-2024 10:21 PM by C.Ret.)
Post: #2
RE: (10C or 25C) Distance Speed Time
(05-13-2024 10:43 AM)Gamo Wrote:  Input 0 for one of the three unknowns

Dear GAMO,

Thank you for this code for the fabulous HP-25 as well as for the brilliant idea of indicating unknown values to be determined by a zero value.

If I understand correctly, one must enter the three parameters distance, speed, and time in their respective registers using STO 1, STO 2, and STO 3, indicating by a zero value the unknown value one wishes to see displayed.

Thus, one and only one of the three registers must be zero.

Consequently, there aren't as many tests to perform as one might think; with a bit more logic, the code can be significantly shortened.

For example, if we perform the product of speed by time and the result is non-zero, then we know that it is the distance that is zero or unknown. Yet we have precisely just calculated it by performing the previous product!

If, on the other hand, the product of speed by time is null, then we know that the distance is a known value and thus it must be divided either by speed (to get time) or by time (to get speed). Since either speed or time is zero, dividing the distance by their sum will give the result expected by the operator.

There are therefore only two operations to perform to calculate the unknown data: either the multiplication of speed by time or the division of distance by the sum of speed and time.

Well, I must admit that one small detail considerably complicated the implementation of my idea; it is the conversion of time into decimal hour and a hexadecimal time as in your initial code.

But the HP-25/25C calculators are full of resources.

So, I managed to create a code that functions exactly like yours and produces the same results in just 14 steps:



01 RCL 2
02 RCL 3
03 →H
04 STO - 2
05 ×
06 x≠0 ?
07 GTO 00
08 RCL 1
09 RCL 2
10 ÷
11 x>0 ?
12 →H.MS
14 ABS


On step 06, the product of speed × time is tested. If it is non-zero, we simply compute the unknown distance and GTO 00 to display it.

At step 10, the known distance is divided by the speed or the negated time, computing respectively a positive time or a negative speed.

I used a negated time as a flag to avoid the conversion to H.mmss in the case of speed computation. The final ABS instruction is needed to remove the negative sign in case of speed computation.

Thank you for sharing your code and thoughts; your code and nice idea really inspire me.
Find all posts by this user
Quote this message in a reply
05-14-2024, 01:25 AM
Post: #3
RE: (10C or 25C) Distance Speed Time
Brilliant!
We can even do without registers:
Code:
01: 15 00    : g ->H
02: 32       : CHS
03: 15 71    : g x=0
04: 21       : x<->y
05: 61       : *
06: 15 61    : g x<>0
07: 13 13    : GTO 13
08: 22       : Rv
09: 14 73    : f LASTx
10: 71       : /
11: 15 51    : g x>=0
12: 14 00    : f ->H.MS
13: 15 03    : g ABS

Examples

12 ENTER 5 ENTER 0 R/S

2.2400


12 ENTER 0 ENTER 2.24 R/S

5.0000


0 ENTER 5 ENTER 2.24 R/S

12.0000
Find all posts by this user
Quote this message in a reply
05-14-2024, 04:03 AM
Post: #4
RE: (10C or 25C) Distance Speed Time
C.Ret

Thanks for the interest of this program and the more refine routine.

I have try your program and some procedure not work as expected.

I will use the example from the HP-12C edition to show you.

Example Problem:

Cycling distance is 35.08 km and took 2 hour 2 minute and 15 second

►What is the Average Speed?

►If to take 1 hour 30 minute What is the Average Speed?

►If the speed is 25 km/h How long it take to cover 35.08 km?

35.08 [STO] 1 // Input Distance

0 [STO] 2 // Unknown Speed

2.0215 [STO] 3 // Input Time

⁕[R/S] 17.2172 ≈ 17.2 km/h // Average Speed Result

1.3 [STO] 3 // Change Time Input

⁕[R/S] 23.3867 ≈ 23.4 km/h // Update the Average Speed

25 [STO] 2 // Input new data for Speed

0 [STO] 3 // Unknow Time

⁕[R/S] 1.24 ≈ 1 hour 24 minute // Update Time Result

------------------------------------------------------------
Your routine some data is not intact when input the two
variables and zero on the unknown. When making data
change the answer is wrong.

The first example is to find Speed and when user change

the Time to solve for the new Speed its doesn't work.
-------------------------------------------------------------

Thank You

Gamo
Find all posts by this user
Quote this message in a reply
05-14-2024, 04:14 AM
Post: #5
RE: (10C or 25C) Distance Speed Time
Thomas Klemm

Thanks for the interest of this program and

your Stack Only program is fantastic !!

But when user need to update data it always have

to put all "complete data on the stack" every time.

Otherwise it is still a good program in it own way.

Like mine program version its just the simple straightforward approach.

Thank You

Gamo
Find all posts by this user
Quote this message in a reply
05-14-2024, 05:12 AM (This post was last modified: 05-14-2024 05:40 AM by Thomas Klemm.)
Post: #6
RE: (10C or 25C) Distance Speed Time
(05-14-2024 04:14 AM)Gamo Wrote:  But when user need to update data it always have to put all "complete data on the stack" every time.

Here's the mix of C.Ret's and my program:
Code:
01: 24 02    : RCL 2
02: 24 03    : RCL 3
03: 15 00    : g ->H
04: 61       : *
05: 15 61    : g x<>0
06: 13 00    : GTO 00
07: 24 01    : RCL 1
08: 24 02    : RCL 2
09: 14 73    : f LASTx
10: 41       : -
11: 71       : /
12: 15 51    : g x>=0
13: 14 00    : f ->H.MS
14: 15 03    : g ABS

It doesn't modify the registers anymore.
Find all posts by this user
Quote this message in a reply
05-18-2024, 09:21 AM (This post was last modified: 05-18-2024 09:46 AM by C.Ret.)
Post: #7
RE: (10C or 25C) Distance Speed Time
(05-14-2024 04:03 AM)Gamo Wrote:  Your routine some data is not intact when input the two
variables and zero on the unknown. When making data
change the answer is wrong.

This remark is entirely relevant. I am a very lazy programmer and to save a ridiculous byte, I used the R2 register to store the converted time xor the speed by performing a subtraction in order to use the sign as the signal for the final conversion. This explains why my code gives erroneous results if the user does not restore the value in register R2.
I could have used another register, but that would have made the code a little longer. Unlike Thomas, I didn't have the brilliant idea of using the LASTx register to memorize one of the non-zero parameters.

I must admit that Thomas's latest version is the best compromise using the four registers without modifying the three data input ones.


01: 24 02    :   RCL 2      // Speed
02: 24 03    :   RCL 3      // Time (h.mms)
03: 15 00    : g →H         // convert Time to h.hhh
04: 61      :    ×         // compute distance and store decimal Time in the LASTx register
05: 15 61    : g x≠0       
06: 13 00    :   GTO 00     // Display computed Distance
07: 24 01    :   RCL 1      // Distance
08: 24 02    :   RCL 2      // Speed (or zero)
09: 14 73    : f LASTx       // Time (h.hhh) (or zero)
10: 41      :    -
11: 71      :    ÷        // Compute Time XOR negated Speed
12: 15 51    : g x≥0
13: 14 00    : f →H.MS      // back-convert Time
14: 15 03    : g ABS       // make Speed positive
Find all posts by this user
Quote this message in a reply
05-18-2024, 11:53 PM (This post was last modified: 05-18-2024 11:54 PM by Johnh.)
Post: #8
RE: (10C or 25C) Distance Speed Time
Very useful ideas, for finding a third unknown when any two out of three variables are known.

Lots of other such simple cases come up in daily engineering. eg, electrical design, with capacitors, variables being frequency, impedance and capacitance.

Similar for inductance

Structures, stiffness properties of a rectangular beam: variables depth, width and Moment of inertia (I)

Mechanics: Acceleration, time, change in velocity.

Convective cooling: temperature difference, convection coefficient, rate of heat loss
Find all posts by this user
Quote this message in a reply
05-20-2024, 09:23 AM (This post was last modified: 05-20-2024 09:38 AM by Gamo.)
Post: #9
RE: (10C or 25C) Distance Speed Time
Program update from post #1

A little shorter version.

Quote:01 RCL 3
02 X=0
03 GTO 15
04 →H
05 RCL 2
06 X=0
07 GTO 10
08 x // Calculate Distance = Speed x Time
09 GTO 00
10 R↓
11 RCL 1
12 X<>Y
13 ÷ // Calculate Speed = Distance ÷ Time
14 GTO 00
15 RCL 1
16 RCL 2
17 ÷
18 →H.MS // Calculate Time = Distance ÷ Speed

Gamo
Find all posts by this user
Quote this message in a reply
05-20-2024, 11:41 AM
Post: #10
RE: (10C or 25C) Distance Speed Time
(05-20-2024 09:23 AM)Gamo Wrote:  A little shorter version.

Code:
01: 24 01    : RCL 1
02: 24 03    : RCL 3
03: 15 71    : g x=0
04: 13 14    : GTO 14
05: 15 00    : g ->H
06: 24 02    : RCL 2
07: 15 71    : g x=0
08: 13 11    : GTO 11
09: 61       : *
10: 13 00    : GTO 00
11: 22       : Rv
12: 71       : /
13: 13 00    : GTO 00
14: 22       : Rv
15: 24 02    : RCL 2
16: 71       : /
17: 14 00    : f ->H.MS
Find all posts by this user
Quote this message in a reply
Post Reply 




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