07-28-2017, 10:00 PM
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:
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
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