Interchangable Solutions using Formula EVAL Module
07-28-2017, 10:00 PM (This post was last modified: 07-31-2017 04:55 AM by gjmcclure.)
Post: #1
 gjmcclure Junior Member Posts: 28 Joined: Jul 2014
Interchangable Solutions using Formula EVAL Module
The Interchangable Solutions Module (INTSOLN.MOD) when combined with the SIROM Module is a nice way to solve equations, and quite a few examples are given. I have rewritten a couple sections of the SLV+ routine to allow it to use the SV$program in the Formula EVAL Module (currently EVAL_1E.MOD). Here is the new LIBSV$ routine (Solve equation from library) and an example using Ohm's Law for the equation to solve:

Quote:01 LBL "LIBSV$" 02 SF 27 ' SET USER MODE 03 CLX ' CLEAR KEY ASSIGNMENTS FOR A-E 04 LKAX 05 LBL F ' NEW EQUATION RESTART 06 "EQ NAME: " ' GET EQUATION (6 CHARS OR LESS) 07 PMTA 08 ASTO 06 ' STORE IN 6 09 LBL 01 10 CF 04 11 CF 05 12 SF 06 13 XEQ IND 06 ' GET EQUATION PARAMS PROMPT 14 ALENG ' DETERMINE NUMBER OF PARAMS 15 E1 16 X<Y? 17 SF 05 18 CLX 19 9 20 X<=Y? 21 SF 04 22 CF 22 23 PROMPT 24 GTO 01 ' NOTHING ENTERED, ASK FOR PARAMS AGAIN 25 LBL A ' 1ST PARAM ENTERED / TO BE SOLVED 26 E 27 GTO 02 28 LBL B ' 2ND PARAM ENTERED / TO BE SOLVED 29 2 30 GTO 02 31 LBL C ' 3RD PARAM ENTERED / TO BE SOLVED 32 3 33 GTO 02 34 LBL D ' 4TH PARAM ENTERED / TO BE SOLVED IF VALID 35 FS? 05 36 SF 04 37 FC? 04 38 GTO 01 39 4 40 GTO 02 41 LBL E ' 5TH PARAM ENTERED / TO BE SOLVED IF VALID 42 FC? 05 43 GTO 01 44 5 45 LBL 02 ' COMMON PARAM HANDLING 46 FC? 22 ' WAS IT ENTERED? 47 GTO 00 ' NO MUST NEED TO BE SOLVED 48 X<>Y 49 STO IND Y ' SAVE IN REG 01 THRU REG 05 50 GTO 01 51 LBL 00 52 STO 00 ' SAVE LOCATION TO SOLVE 53 RCL 01 ' SAVE PARAMS TO a THRU e 54 STO L 55 RCL 02 56 RCL 03 57 RCL 04 58 RCL 05 59 SF# 4 (ST>B7) ' ENTER AS SF$ ST>B7
61 E-99 ' ASSUME VIRTUAL 0 AND 1 FOR GUESSES
62 E
63 "a^b=?"
64 PROMPT ' GET BETTER GUESSES IF SUPPLIED
65 CF 06
66 XEQ IND 06 ' GET SV$COMPATIBLE EQUATION TO SOLVE 67 XROM "SV$" ' SOLVE IT!
68 STOP
69 GTO 01 ' GET NEXT PARAMS

70 LBL J ' EXIT ROUTINE, RESTORE USER PARAMS
71 E
72 LKAX
73 END

====================

01 LBL "OHMS" ' EXAMPLE, OHM'S LAW, V=I*R
02 FS? 06 ' GOTO LBL 6 TO DISPLAY ENTRY PROMPT
03 GTO 06
04 RCL 00 ' STORE VARIABLE TO SOLVE
05 GTO IND 00 ' PICK EQUATION BASED ON THAT VARIABLE

06 LBL 01 ' SOLVING FOR V
07 "b*c-X"
08 RTN

09 LBL 02 ' SOLVING FOR I
10 "X*c-a"
11 RTN

12 LBL 03 ' SOLVING FOR R
13 "b*X-a"
14 RTN

15 LBL 06 ' DISPLAY
16 "V I R"
17 END

Notice that the variable to solve must be replaced with X, and that the variables (max of 5 allowed) are automatically put into a thru e (buffer 7). It is a little more complicated to enter the user equation, but much clearer on how it is being solved.

RAW files for the above program are attached.

Greg

Attached File(s)
LIBSV$andOHMS.zip (Size: 478 bytes / Downloads: 4) 07-30-2017, 10:27 PM (This post was last modified: 07-31-2017 04:58 AM by gjmcclure.) Post: #2  gjmcclure Junior Member Posts: 28 Joined: Jul 2014 RE: Interchangable Solutions using Formula EVAL Module After posting LIBSV$ above I took another look at it and realized I didn't like having to have a different equation for each variable to be solved. Going back to the original SLV+ from the Interchangable Solutions, I realized that FROOT still needs to be called. But a couple things can be done to make equation entry easier... so here is the revised routines.

FROOT can either be from SIROM or from SMATH modules. In fact you can still use the SLV+ from interchangeable solutions, but I added a couple labels to allow entry of a different equation (LBL F), and easy exit with restore of user key assignments (LBL J). However, the user equations need to be written differently to take advantage of EVAL$. Here are the revised routines: Quote:01 LBL "SLVEQ$"
02 SF 27 ' SET USER MODE
03 CLX ' CLEAR KEY ASSIGNMENTS FOR TOP TWO ROWS
04 LKAX

05 LBL F ' NEW EQUATION RESTART
06 "EQ NAME: " ' GET EQUATION (6 CHARS OR LESS)
07 PMTA
08 ASTO 06 ' STORE IN 6

09 LBL 01
10 CF 04
11 CF 05
12 SF 06
13 XEQ IND 06 ' GET EQUATION PARAMS PROMPT
14 ALENG ' DETERMINE NUMBER OF PARAMS
15 E1
16 X<Y?
17 SF 05
18 CLX
19 9
20 X<=Y?
21 SF 04
22 CF 22
23 PROMPT
24 GTO 01 ' NOTHING ENTERED, ASK FOR PARAMS AGAIN

25 LBL A ' 1ST PARAM ENTERED / TO BE SOLVED
26 E
27 GTO 02

28 LBL B ' 2ND PARAM ENTERED / TO BE SOLVED
29 2
30 GTO 02

31 LBL C ' 3RD PARAM ENTERED / TO BE SOLVED
32 3
33 GTO 02

34 LBL D ' 4TH PARAM ENTERED / TO BE SOLVED IF VALID
35 FS? 05
36 SF 04
37 FC? 04
38 GTO 01
39 4
40 GTO 02

41 LBL E ' 5TH PARAM ENTERED / TO BE SOLVED IF VALID
42 FC? 05
43 GTO 01
44 5

45 LBL 02 ' COMMON PARAM HANDLING
46 FC? 22 ' WAS IT ENTERED?
47 GTO 00 ' NO MUST NEED TO BE SOLVED
48 X<>Y
49 STO IND Y ' SAVE IN PROPER REGISTER
50 GTO 01

51 LBL 00
52 STO 00 ' SAVE LOCATION TO SOLVE
53 E-99 ' ASSUME VIRTUAL 0 AND 1 FOR GUESSES
54 E
55 "a^b=?"
56 PROMPT ' GET BETTER GUESSES IF SUPPLIED
57 CLA
58 ARCL 06
59 CF 06
60 FROOT
61 STOP
62 GTO 01 ' GET NEXT PARAMS

63 LBL J ' EXIT ROUTINE, RESTORE USER KEY ASSIGNMENTS FOR TOP TWO ROWS
64 E
65 LKAX
66 END

========REQUIRED ROUTINE=========

01 LBL "2B7" ' COPIES REGS 01 THRU 05 INTO BUFFER 7 VARIABLES a THRU e
02 RCL 01
03 STO L
04 RCL 02
05 RCL 03
06 RCL 04
07 RCL 05
08 "XYZTL" ' CAN USE ST>B7 FUNCTION (SF# 4) BUT DISPLAY IS WIERD
09 SHFL
10 END

=====THIS IS SAMPLE EQUATION=====

01 LBL "OHMS" ' EXAMPLE, OHM'S LAW, V=I*R
02 FS? 06 ' GOTO LBL 6 TO DISPLAY ENTRY PROMPT
03 GTO 00
04 STO IND 00 ' STORE FROOT SUPPLIED X IN PROPER PLACE
05 XEQ "2B7" ' SETUP FOR EVAL$06 "b*c-a" ' OHMS LAW EQUATION (RIGHT SIDE - LEFT SIDE) 07 EVAL$
08 RTN

09 LBL 00 ' DISPLAY
10 "V I R"
11 END

I have included a ZIP file with the above TXT file and RAW files. As you can see, setting up the user equation is easier (just one line for EVAL$to use). Use a thru e for the 5 parameters, use right_side - left_side for the equation to evaluate with EVAL$. Be sure to add XEQ "2B7" before doing EVAL$to insure a thru e are filled in. Greg Attached File(s) SLVEQ$.zip (Size: 1.65 KB / Downloads: 2)
08-10-2017, 02:32 PM
Post: #3
 gjmcclure Junior Member Posts: 28 Joined: Jul 2014
RE: Interchangable Solutions using Formula EVAL Module
Here is another sample equation for SLVEQ$, it solves any variable for Time Value of Money equation. Flag 0 is used to choose begin mode (set) or end mode (clear)... Quote:01 LBL "TVM" 02 FS? 06 03 GTO 00 04 STO IND 00 05 XEQ "2B7" 06 CLA 07 FS? 00 08 "(1+b)*" 09 >"c*((1-(1-b)^#d" 10 >")/b)" 11 EVAL$
12 "a+X+e(1+b)^#d"
13 EVAL\$
14 RTN

16 LBL 00
17 "PV I PM N FV"
18 END

Greg
 « Next Oldest | Next Newest »

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