Example of MISO solver for WP 34s

05222018, 09:29 AM
(This post was last modified: 05222018 10:06 AM by gomefun2.)
Post: #1




Example of MISO solver for WP 34s
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. This is a MISO solver meaning that each time the program is run a different variable can be solved for, without having to rewrite the equation. This program will have named variables.
The equation the program will solve is Darcy's equation for SteadyState Flow. This is equation 6.4 on page 6.3 at http://infohost.nmt.edu/~petro/faculty/E...idflow.pdf This is a 10 variable equation, with a worked example (at the link) so you can test the code to see if it worked for you. 70 LINES (71 LINES including the final END) (NOTE: I use // for commenting the code) LBL A //using this label assigns the program to the physical 'A button' on the calculator CLα // clears the alpha registry 1 // puts 1 in the x registry STO 00 // stores 1 into R00. R00's only purpose is to act as a pointer to the memory location. storing 1 into R00 means that R00 will point to the registry R01 (see below for example). α's' // alpha's' puts s into the alpha registry XEQ'VAR' // calls and executes the code at LBL'VAR' α'Pe' // alpha'Pe' puts Pe into the alpha registry XEQ'VAR' // calls and executes the code at LBL'VAR' α'Pwf' // alpha'Pwf' puts Pwf into the alpha registry XEQ'VAR' // calls and executes the code at LBL'VAR' α'q' // alpha'q' puts q into the alpha registry XEQ'VAR' // calls and executes the code at LBL'VAR' α'Bo' // alpha'Bo' puts Bo into the alpha registry XEQ'VAR' // calls and executes the code at LBL'VAR' α'u' // alpha'u' puts u into the alpha registry XEQ'VAR' // calls and executes the code at LBL'VAR' α'k' // alpha'k' puts k into the alpha registry XEQ'VAR' // calls and executes the code at LBL'VAR' α'h' // alpha'h' puts h into the alpha registry XEQ'VAR' // calls and executes the code at LBL'VAR' α're' // alpha're' puts re into the alpha registry XEQ'VAR' // calls and executes the code at LBL'VAR' α'rw' // alpha'rw' puts rw into the alpha registry XEQ'VAR' // calls and executes the code at LBL'VAR' RCL 99 // This recalls the location of output variable in memory (see the subfunctions below) STO 00 // This stores the location from R99 into R00 SLV'SSR' // This solves function at LBL'SSR' (steadystate radial) RTN // End of Main Function LBL 'SSR' // This is where the Equation is stored STO>00 // This stores whatever is in the X register to the location that is stored in R00. For example, if R00 contains 2, then the X register is stored to R02. The STO> is different than STO (> is for memory address location) // STO>00 has no impact on the equation. The reason it is used is that it tells the calculator which variable to solve for. Whichever variable appears first after LBL'SSR' is the variable the calculator will solve for. By storing 5 into R00, and calling STO>00 as the first line in the equation, the calculator will store a random number into R05. But since R05 appears first the calculator will also solve for this registry as the unknown. It basically tricks the calculator to solving for any variable in the equation. RCL 07 // recall k RCL 08 // recall h * // multiply them RCL 02 // recall Pe RCL 03 // recall Pwf  // subtract them * // multiply #002 // # is for small integers (0255) this will put the number 2 into the x registry SDR 001 // shifts the decimal place once to the right turn 2 into 0.2 #141 // puts 141 into the x registry + // adds 0.2 and 141 to make 141.2 (the constant in the equation) RCL 06 // u * // multiply RCL 05 // Bo * // multiply RCL 09 // re RCL 10 // rw / // divide LN // natural logarithm RCL 01 // s + // addition * // multiply / // divide RCL 04 // q  // subtract (for the solver to work the equation must be equal to zero (f(x) = 0), so I subtracted q from both sides) RTN // End of the equation subfunction LBL'VAR' // The purpose of this subfunction is to help save space when storing data to registers (these are repetive steps). α'?' // alpha'?' adds a question mark to alpha register, this just makes the prompt look nicer RCL>00 // the > means this is an address recall. So this line recalls the value stored in the register at the location stored in R00. For example if R00 contains 3, the value stored in R03 is recalled. The purpose of this is to show the user what is currently stored in each variable. PROMPT // This waits for user input (when running the program, key in a number and push R/S to enter the value) STO>00 // Similar to RCL>00 above the > tells the calculator to store the value in the x register to the location stored in R00. x<0? // this is a test to see if the user input a negative number. The reason this is here is that all the numbers (aside from 's' in the equation must be positive. If a number is an input as negative then this tells the calculator to solve for that variable. It is just a way I decided to trick the calculator to solve for the correct variable. Since S can be negative I put it first, therefore the calculator will only solve for s (even if it is negative) only if all other variables are positive). x<0? is a conditional statement, if true, it will execute the next line of code, if false it will skip the next line of code. XEQ'UNK' // this line executes only if the user puts a negative number in for the current variable. This function stores which variable is the one that should be solved for. INC 00 // this increments R00, this puts a new value into R00, and since R00 is being used as the address locations in the memory this will increment the memory location to the next location. For example, if the program just stored a value into R02, this will increment the program so that the next iteration of the program will store a value into R03. CLα // Clears the alpha registry RTN // Ends the subfunction returns to the entry point in the main function LBL'UNK' // This subfunction stores into memory the variable that should be solved for. RCL 00 // Recalls the memory location stored in R00 STO 99 // Stores the location to R99. Since s is the first variable in the code, even if it is negative, the next iteration with a negative number (the one that actually wants to be solved for) will store its value here overtop the location of s. (s is the only number that could naturally be negative). s is only solved for if it is the only negative number. RTN // ends the subfunction END // Final End This code could probably be modified slightly to make a general purpose MISO solver. I might end up writing that code next. At any rate if anyone has a better way to do this code please let me know. I hope this helps at least one other person because it took me a while to figure this out. Thanks to Dieter on the forum for helping, and also the WP 34s manual. (NOTE: if it isn't clear from the code, the calculator solves for the variable whose initial guess is negative, since these variables are not naturally negative. That is how it decides). 

« Next Oldest  Next Newest »

Messages In This Thread 
Example of MISO solver for WP 34s  gomefun2  05222018 09:29 AM
RE: Example of MISO solver for WP 34s  Dieter  05222018, 05:40 PM
RE: Example of MISO solver for WP 34s  Dieter  05222018, 07:43 PM
RE: Example of MISO solver for WP 34s  burkhard  05232018, 05:47 PM
RE: Example of MISO solver for WP 34s  Dieter  05232018, 07:36 PM
RE: Example of MISO solver for WP 34s  Dieter  05242018, 06:17 PM
RE: Example of MISO solver for WP 34s  gomefun2  05232018, 09:57 PM

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