The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function

 (42S, Free42, DM42) Solving for HMS values
10-08-2020, 12:44 PM
Post: #1
 Werner Senior Member Posts: 888 Joined: Dec 2013
(42S, Free42, DM42) Solving for HMS values
Solving for HMS values may introduce wrong values.

An example.
Suppose your daily commute counts as working hours, except for the first 20 minutes each way.
Say your commute is 1 hour, each way, and you have a lunch break of half an hour.
Your daily working time is set to 7:36.
If you leave home at 7:15, when would you then be allowed to leave the office, to ensure a full day's work?

Given
LH: the time you Leave Home in the morning
C: the duration of your Commute, one-way
LB: Lunch Break
when would you be allowed to leave the office (LO)?

The moment you arrive back home is:

LH + 20m + WT + LB + 20m
so
LO = LH + WT + LB + 40m - C

if your commute is less than 20 minutes, it is

LO = LH + WT + LB + C

Try a solver program (for now only for C>20m):

Code:
 LBL "FW"  MVAR "WT"  MVAR "LH"  MVAR "LB"  MVAR "C"  MVAR "LO"  RCL "LH"  RCL "WT"  HMS+  RCL "LB"  HMS+  0.4  HMS+  RCL "C"  HMS-  RCL "LO"  HMS-  END

SOLVE "FW", enter
WT = 7.36
LH = 7.15
LB = 0.30
C = 1

solve for LO with guesses 0 and 16 and get 14.6060 - which ought to be 15.0100.
(the guesses are not really necessary but force the result)
This value is equivalent to 15.01, as you can see when you do 0 HMS+.
There is however no way to tell the solver to only use valid H.MS values.
So we'll have to correct the solved value. Since we may also run into accuracy problems (eg 14.60599999..)
we will build a front-end to the solver, and round the value obtained to the nearest minute.
This time we include the case where C is less than 20m as well, as follows:

Let's make the Forfait of 20m a variable as well (FF).
Since FF and WT are variables that won't change often, we'll put them on the next page, using a dummy " " variable:

Code:
00 { 114-Byte Prgm } 01▸LBL "FW" 02 MVAR "LH" 03 MVAR "LB" 04 MVAR "C" 05 MVAR "LO" 06 MVAR " " @ fill up the page 07 MVAR " " 08 MVAR "FF" @ rarely used variables on 2nd page 09 MVAR "WT" 10 FS? 45 @ Solver running flag 11 GTO 00 12 PGMSLV "FW" 13▸LBL 10 @ -- Menu loop -- 14 VARMENU "FW" 15 STOP 16 ASTO ST L @ set up solver 17 CLX 18 STO IND ST L 19 SOLVE IND ST L 20 2ᴇ31 @ round result to the nearest minute, Free42 specific 21 HMS+ 22 LASTX 23 - 24 ASTO ST L 25 STO IND ST L @ store in variable you solved for 26 ├"=" @ show solver message 27 ARCL IND ST L 28 AVIEW 29 CLA 30 ARCL ST L 31 GTO 10 32▸LBL 00 @ -- solver equation -- 33 RCL "FF" 34 ENTER 35 HMS+ 36 RCL "C" 37 HMS- 38 LASTX 39 X>Y? 40 X<>Y 41 RCL "LH" 42 HMS+ 43 RCL "WT" 44 HMS+ 45 RCL "LB" 46 HMS+ 47 RCL "LO" 48 HMS- 49 END

Now, you can observe the difference:
if you use the SOLVER, with the original example, you get 14.606
If you do XEQ "FW" instead, the interface is the same (apart from inputting the guesses), but you get 15.01

In general, if you have a HMS solver program (FW here), we can do
In:
A: "FW"
X: 0.01 @ round to multiple of (in HH.MMSS style so if you want to round to a quarter, use 0.15)
XEQ "HMSLV"

(Of course, for the 42S, change the LSTO statements into STO's)

Code:
00 { 64-Byte Prgm } 01▸LBL "HMSLV" 02 →HR 03 LSTO "R" 04 LSTO "P" 05 ASTO "P" 06 PGMSLV IND "P" 07▸LBL 10 08 VARMENU IND "P" 09 STOP 10 ASTO ST L @ set up solver 11 CLX 12 STO IND ST L 13 SOLVE IND ST L 14 →HR @ round to a multiple of R 15 RCL÷ "R" 16 FP 17 RCL+ ST L 18 IP 19 RCL× "R" 20 →HMS 21 ASTO ST L 22 STO IND ST L @ store in variable you solved for 23 ├"=" @ show solver message 24 ARCL IND ST L 25 AVIEW 26 CLA 27 ARCL "P" 28 GTO 10 29 END

Problem: when you EXIT the VARMENU, the local variables R and P still exist. But when the MENU is shown, they should exist. Dilemma.

Hope you like it,
Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
 « Next Oldest | Next Newest »

 Messages In This Thread (42S, Free42, DM42) Solving for HMS values - Werner - 10-08-2020 12:44 PM RE: (42S, Free42, DM42) Solving for HMS values - rprosperi - 10-08-2020, 10:06 PM RE: (42S, Free42, DM42) Solving for HMS values - Werner - 10-15-2020, 07:44 AM RE: (42S, Free42, DM42) Solving for HMS values - Werner - 10-09-2020, 03:21 AM RE: (42S, Free42, DM42) Solving for HMS values - rprosperi - 10-15-2020, 12:40 PM RE: (42S, Free42, DM42) Solving for HMS values - Albert Chan - 10-15-2020, 01:13 PM

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