Post Reply 
Example of MISO solver for WP 34s
05-22-2018, 07:43 PM (This post was last modified: 05-22-2018 10:08 PM by Dieter.)
Post: #3
RE: Example of MISO solver for WP 34s
(05-22-2018 09:29 AM)gomefun2 Wrote:  I will show an example of how to program a MISO (multiple input single output) solver mapped to a single button press for an equation.
...
At any rate if anyone has a better way to do this code please let me know.

OK, here is my very first, almost untested version, so try it at your own risk ;-)

Code:
001 LBL A
002 CLα
003 # 001
004 STO J
005 CLx
006 STO K
007 α'S'
008 XEQ 99
009 α'Pe'
010 XEQ 99
011 α'Pwf'
012 XEQ 99
013 α'q'
014 XEQ 99
015 α'Bo'
016 XEQ 99
017 α'μ'
018 XEQ 99
019 α'k'
020 XEQ 99
021 α'h'
022 XEQ 99
023 α'Re'
024 XEQ 99
025 α'Rw'
026 XEQ 99
027 RCL K
028 x≥1?
029 GTO 00
030 CLα
031 α'Sel'
032 α'ect'
033 α' Va'
034 α'r !'
035 VIEWα
036 PSE 20
037 GTO A
038 LBL 00
039 STO J
040 # 1/2
041 # 200
042 SLV'SSR'
043 SKIP 001
044 ERR 20
045 RTN
046 LBL 99
047 α'=?'
048 RCL→J
049 PROMPT
050 STO→J
051 x≥0?
052 SKIP 002
053 RCL J
054 STO K
055 INC J
056 CLα
057 RTN
058 LBL'SSR'
059 STO→J
060 RCL 07
061 RCL× 08
062 RCL 02
063 RCL- 03
064 ×
065 # 002
066 SDR 001
067 # 141
068 +
069 RCL× 06
070 RCL× 05
071 RCL 09
072 RCL/ 10
073 LN
074 RCL+ 01
075 ×
076 /
077 RCL- 04
078 RTN

Some remarks:
  • Instead of R00 and R99 (who knows if R99 even exists?) the program uses the J and K registers which are always available. The variable to be solved is stored in K. It is initialized with zero to make sure the user has selected one of the variables as the one to solve for (cf. next point).
    Note: J and K are also used for the parameters of some statistical distributions. So if these are involved you should change J and K to, say, A and B. In this case be sure to start the program with a SSIZE4 command as A and B hold the upper (5th and 6th) stack levels in SSIZE8 mode.
  • The program checks if the user has selected a variable to solve for (cf. line 028). If not, a respective message is displayed and the input routine starts over.
  • Instead of LBL"VAR" the program uses LBL 99 for the input routine. That's much faster to enter. Don't know if this even saves some bytes.
  • I have renamed some variables. The 34s character set includes a µ (switch to lower case and press g(reek) M). Even subscripts are available (though not used here).
  • The clumsy UNK routine was removed completely. If the user has entered a non-negative variable the program simply skips over the two lines that store the index of the solver variable.
  • The implemented equation uses RCL-arithmetics which makes it shorter and more effective. Also the equation was moved to the end of the program.
  • If no root is found an error message appears (ERR 20). Yes, the 34s has a set of predefined messages (MSG) and errors (ERR) that are quite handy in such cases.
  • The solver needs two initial guesses in X and Y. Since the typical values for the variables may vary by some orders of magnitude I've simply set 0,5 and 200 (cf. line 040/041). This definitely is ..."sub-standard". Better ideas: ask the user for two guesses, or arrange the variables in two groups (say, typically less than 10 or more than 10) and derive a guess from the index of the variable to solve for.

    Edit: here's an even better idea. The user enters the solver variable with negative sign to indicate that this is the one to solve for. So simply have the user enter a (negative) guess for this variable. Then start the solver with half and twice that (absolute) value. Example: you want to solve for a variable that should be somewhere near 100. So enter –100 at the respective prompt and the solver will start with 50 and 200. Could this be a good idea? I tried it and it seems to work very well.

I tried the formula in the PDF and solved for q first (result: q=1120,966). Then I changed q to 1000 and solved for µ which was then returned as µ=0,6105.

So far for the moment. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Example of MISO solver for WP 34s - Dieter - 05-22-2018 07:43 PM



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