WP34S - f SLV used with user selectable variables
|
04-27-2015, 03:47 PM
(This post was last modified: 04-29-2015 12:14 AM by CR Haeger.)
Post: #1
|
|||
|
|||
WP34S - f SLV used with user selectable variables
Hello,
I am looking for a way to use the WP34S and f SLV to solve for a user select-able variable in an equation. As a test example, I wrote a short routine (A) that allows for solving for R1, R2 or Req in a parallel resistor equation. I am not sure if this is a practical or the most user friendly way to do this. Feel free to comment, correct or upgrade this! Code:
1000 STO 01 700 STO 03 // store known values (R1, Req in this case) 2 STO 00 // variable to solve for (R2) 1000 5000 f SLV A //initial guesses and then solve A ⇒ 2333.33 // solution 700 =1/(1/1000 +1/2333) |
|||
04-27-2015, 10:15 PM
Post: #2
|
|||
|
|||
RE: WP34S - f SLV used with user selectable variables
It appears that you are not the first one with this idea:
TECHNIQUE: 'SOLVE' AND 'INTEG' WITH "MISO" USER FUNCTIONS ON THE 34C/15C/41C Cheers Thomas |
|||
04-28-2015, 11:51 AM
Post: #3
|
|||
|
|||
RE: WP34S - f SLV used with user selectable variables
(04-27-2015 10:15 PM)Thomas Klemm Wrote: It appears that you are not the first one with this idea: Thank you for the great article link! I certainly expected that these techniques had been developed a while ago - and more fully than my quick attempt above. I especially find the use of this technique to INTEGRATE (versus SOLVE) with respect to a chosen variable very interesting. Best, Carl |
|||
05-03-2018, 03:56 PM
Post: #4
|
|||
|
|||
RE: WP34S - f SLV used with user selectable variables
Thanks for this information I was wondering how to do MISO solver functions on the WP 34s.
But I had a question. If I wanted to use a single equation with 40 variables, clearly using the inputs as R01, R02... ...R40, would not be ideal. What is the best way to make the calculator ask for named variables? My guess is something like: String:"A?" STO R00 String: "B?" STO R01 ... ETC I'm not sure how to code this even... because I am new to this calculator, coming from the HP 35s. This seems as if it would take at least 200 lines of code to program a 40 variable equation (80 lines to store input variables, then 40 lines to recall them, then another 40 lines at least to put the equation in, then 20 (at least) lines for other stuff). Does this calculator only come with 527 lines of memory as the program screen would suggest? Thanks |
|||
05-03-2018, 07:21 PM
(This post was last modified: 05-03-2018 07:27 PM by Dieter.)
Post: #5
|
|||
|
|||
RE: WP34S - f SLV used with user selectable variables
(05-03-2018 03:56 PM)gomefun2 Wrote: But I had a question. If I wanted to use a single equation with 40 variables, 40 variables? Please post the equation – I am really curious. :-) (05-03-2018 03:56 PM)gomefun2 Wrote: My guess is something like: This only writes text to Alpha (and the next one is appended to the previous one). You will have to use PROMPT commands that stop for data entry, and maybe the current value in the respective register should be set as default (else you would have to re-enter all 40 variables). So it will be more like this: Code: CLα You see, there is no INPUT command as featured on the 35s. There also is no equation mode. That's why I think the 35s may be the better option for this task. OK, essentially with 26 possible variables (unless you want to use the indirect registers). (05-03-2018 03:56 PM)gomefun2 Wrote: This seems as if it would take at least 200 lines of code to program a 40 variable equation (80 lines to store input variables, 40 variables with 5 lines each for data entry (see above) = 200 lines. (05-03-2018 03:56 PM)gomefun2 Wrote: then another 40 lines at least to put the equation in, These 40 lines are required only to recall the 40 variables – without any mathematical operations. #-) (05-03-2018 03:56 PM)gomefun2 Wrote: then 20 (at least) lines for other stuff). Does this calculator only come with 527 lines of memory as the program screen would suggest? The 34s comes with a certain amount of memory. You can allocate the required number of data registers by means of the REGS command (in the MODE menu, can be checked with REGS? in the P.FCN menu). The remaining memory can be used for programs. Switch to program mode (P/R) and see the number of available steps in the three-digit display on the right (normally used for the tens exponent). Dieter |
|||
05-03-2018, 10:02 PM
(This post was last modified: 05-03-2018 10:45 PM by gomefun2.)
Post: #6
|
|||
|
|||
RE: WP34S - f SLV used with user selectable variables
There are a lot of problems I solve that require an excess of 100 variables. I programmed an Excel spreadsheet (in VBA) to calculate pressure drop (Beggs Brill/Modified Hagedorn and Brown Method (With Griffith Correlation)) and I remember counting more than 100 variables and 17 sub-functions.
For a single equation, there are quite a few that I use that have ten or more variables that rely on other equations with just as many variables. Of course, you could look at the Navier-Stokes Equation, and program a general solver (although I have never wanted to do this): https://www.grc.nasa.gov/www/k-12/airplane/nseqs.html I was thinking more of the Material Balance Equation: http://www.fekete.com/SAN/WebHelp/Fekete...Theory.htm The basic form has 33 pieces (maybe a couple pieces repeat). I've heard there are more complex forms of this equation. Such as MBE for gas condensate reservoirs, that I get to learn about in my final year of engineering school (start next fall), and I am unsure the form they take in material balance. I assume they are more complex (so I estimated 40 variables), but I am unsure. At any rate, I'll look at what you have here. The main reasons I don't like the hp 35s at the moment are 1) only 26 program labels (A to Z) 2) can't solve and integrate the same function at the same time in the same program If only we could solder a bigger memory chip to the calculator board. I'm not sure why this isn't possible, I just assume it isn't, otherwise people would have done this already. EDIT: You made me interested to check different material balances that I might learn about next year. The Walsh Formulation is a single equation with (at least) 43 pieces and is used for the material balance of a volatile oil. I haven't used this equation yet, so it could be more complex than that but that's what I counted. It is at the bottom of that page I linked at fekete.com, but it is split into 3 pieces. The reason they do that is to make it more manageable (and to linearize it), but really as a single equation it would have over 40 variables (some repeating). I haven't learned the equation yet, but it would take the form F = Eg*N*m + Eo*N (based on my knowledge of the general MBE), and the F, Eg, and Eo terms would be those long equations near the bottom of the page. |
|||
05-04-2018, 12:56 PM
(This post was last modified: 05-04-2018 01:15 PM by Dieter.)
Post: #7
|
|||
|
|||
RE: WP34S - f SLV used with user selectable variables
(05-03-2018 10:02 PM)gomefun2 Wrote: There are a lot of problems I solve that require an excess of 100 variables. I programmed an Excel spreadsheet (in VBA) to calculate pressure drop (Beggs Brill/Modified Hagedorn and Brown Method (With Griffith Correlation)) and I remember counting more than 100 variables and 17 sub-functions. I'd say that a calculator may not be the right tool for this, and you should better stick to Excel or another program that suits this application even better. If you still want to use the 34s for this, here is a much shorter input routine that does not require separate prompts for each and every single variable (and thus 26x5 = 130 steps for A...Z): Code: #026 Note: if you're not yet familiar with the 34s, the first three lines are just a fancy way of writing 1,026. ;-) The routine may be updated for more than 26 variables, for instance by calling them ...X, Y, Z, A2, B2, C2, ... Or switch to lower case: X, Y, Z, a, b, c, ... Dieter |
|||
05-05-2018, 07:35 PM
(This post was last modified: 05-05-2018 11:24 PM by gomefun2.)
Post: #8
|
|||
|
|||
RE: WP34S - f SLV used with user selectable variables
(05-04-2018 12:56 PM)Dieter Wrote:(05-03-2018 10:02 PM)gomefun2 Wrote: There are a lot of problems I solve that require an excess of 100 variables. I programmed an Excel spreadsheet (in VBA) to calculate pressure drop (Beggs Brill/Modified Hagedorn and Brown Method (With Griffith Correlation)) and I remember counting more than 100 variables and 17 sub-functions. I got your code to work, and I have 3 questions: 1) How do I know what letters correspond to what number in the x->alpha step (what page in the manual is the relationship between the number and the alpha symbol)? (how does 65.026 > A?, I don't see this anywhere in the manual). EDIT: I found using the alpha->x command will give me the codes for the letters, but still where is the complete list for this? EDIT 2) are the codes in "Appendix E: Character Sets"? Do I have to convert those base 16 numbers to base 10 to use them for the x->alpha command? I'm not a computer engineer so I never even really learned base 16, I'm just guessing here lol. 2) How does the loop know to stop after 26 characters? (EDIT: I think I figured this one out ISG>cccccc.fffii where ii = 1 because it is not otherwise specified.) this compares R00 with fff, fff is incremented by ii each iteration. 3) How do you combine multiple letters such as "Pr", or "Xr", instead of just one character? (do you just add another character without using CLalpha)? EDIT: new Question 4) is #000 used as a short integer format? so it saves memory to use this for any number between 0 and 255? EDIT: new Question 5) Is there any way to store a single number in the form of 656667686970. such that the program will move read two characters each time it loops (ABCDEF), and translate it into different characters. This way I could use a similar loop as the one you have there, but I would be able to get characters in any order (not just A, B, C, but X, M, R, etc?) This would be like a list... the only guess I have how to do this would be to set R90 to R99 as the list and store the corresponding numbers in those registries. But does this calculator have a better way to do this? |
|||
05-06-2018, 08:47 AM
(This post was last modified: 05-06-2018 09:58 PM by Dieter.)
Post: #9
|
|||
|
|||
RE: WP34S - f SLV used with user selectable variables
(05-05-2018 07:35 PM)gomefun2 Wrote: 1) How do I know what letters correspond to what number in the x->alpha step (what page in the manual is the relationship between the number and the alpha symbol)? (how does 65.026 > A?, I don't see this anywhere in the manual). Appendix E. But you don't need that table for this purpose – it's just simple ASCII: A=65 ... Z=90, a=97...z=122. Yes, the table uses hexidecimal notation, so "41" for "A" means 4*16+1 = 65 decimal. (05-05-2018 07:35 PM)gomefun2 Wrote: 2) How does the loop know to stop after 26 characters? (EDIT: I think I figured this one out ISG>cccccc.fffii where ii = 1 because it is not otherwise specified.) this compares R00 with fff, fff is incremented by ii each iteration. Right. It's the same as on your 35s which you should be familiar with. And the same as on most HPs since the late Seventies. Essentially this sets up a for-next loop: for i = 1 to 26 here is 1,026. You can even set a step size in the 4th and 5th decimal. So 1,01502 counts 1, 3, 5, ... 13, 15. (05-05-2018 07:35 PM)gomefun2 Wrote: 3) How do you combine multiple letters such as "Pr", or "Xr", instead of just one character? (do you just add another character without using CLalpha)? In Alpha mode usually one character is one program line. But there is a way to combine up to three characters in one line: press f Alpha twice. In program mode this will show α' and now you can enter the two characters for "=?" in a single line. Otherwise it's one character per line. In any case each Alpha entry is appended to the existing one. So two three-character-lines give a six-character string in Alpha. (05-05-2018 07:35 PM)gomefun2 Wrote: EDIT: new Question 4) is #000 used as a short integer format? so it saves memory to use this for any number between 0 and 255? Yes. These short integers are faster and require less memory than individual digits. Unlike for instance the HP41 or HP35s the WP34s cannot put a complete number like 1,026 or 4711,0815 in a single line. But by means of short integers and the comma-shifting commands SDR and SLR there is a way to come close in many cases. (05-05-2018 07:35 PM)gomefun2 Wrote: EDIT: new Question 5) Is there any way to store a single number in the form of 656667686970. such that the program will move read two characters each time it loops (ABCDEF), and translate it into different characters. On a programmable calculator there always is a way. Of course this can be programmed. For instance this way: turn the 656667686970 into 0,656667686970 and then multiply by 100 to get the first character, then take the fractional part and continue: Code: LBL 99 656667686970 XEQ 99 => "ABCDEF" Remember, even in SP mode the 34s supports up to 16 digits. In the same manner you could set up a routine that prompts for A, B, C, D, E and F, one after another. Edit: another option is using the αSTO and αRCL commands. Here a string is represented as a number in base 256 (!). So "ABCDE" is stored as 280284578885. Try it: enter this number in X, clear Alpha and recall the number with αRCL X (simply press f RCL). (05-05-2018 07:35 PM)gomefun2 Wrote: This way I could use a similar loop as the one you have there, but I would be able to get characters in any order (not just A, B, C, but X, M, R, etc?) This would be like a list... the only guess I have how to do this would be to set R90 to R99 as the list and store the corresponding numbers in those registries. But does this calculator have a better way to do this? There always is a better way. But this requires detailled and precise information on what exactly (!) you want to achieve. Dieter |
|||
05-06-2018, 11:36 PM
(This post was last modified: 05-06-2018 11:53 PM by gomefun2.)
Post: #10
|
|||
|
|||
RE: WP34S - f SLV used with user selectable variables
If I want to store a single number such as 0.8175728566800069800087820069820087 for ASCII. do I have to do something like:
001: LBL A 002: #009 // number of variables 003: SDR 003 // putting 009 into fff, as in cccccc.fffii 004: STO 00 // Store 0.009 to R00 005: CLα // clear alpha registry 00: DBLON // turn double mode on for more than 8 letters stored in single number // ASCII codes: q(81),k(75),h(72),u(85),B(66),Pe(80/69),Pw(80/87)),re(82/69),rw(82/87) // create the number 0.8175728566800069800087820069820087 for ASCII // an extra 00 after 80, and 82 used to tell the program subfunction, that there are two letters for // that variable 00: #087 00: SDR 003 00: #20 00: + 00: SDR 002 00: #98 00: + 00: SDR 002 00: #006 00: + 00: SDR 003 00: #82 00: + 00: SDR 002 00: #087 00: + 00: SDR 003 00: #00 00: + 00: SDR 002 00: #98 00: + 00: SDR 002 00: #006 00: + 00: SDR 003 00: #80 00: + 00: SDR 002 00: #66 00: + 00: SDR 002 00: #85 00: + 00: SDR 002 00: #72 00: + 00: SDR 002 00: #75 00: + 00: SDR 002 00: #81 00: + 00: SDR 002 00: GTO 99 // sub-function that transforms x-reg to variable names 00: DBLOFF 00: LBL 99 // converts what is in the x-registry to variable names and stores the user input 00: CLα // clear alpha registry 00: Since to put such a long number takes so many steps, is this really more efficient, than just using f-alpha-Enter? (for variable prompts?) if this long number could be entered in 1 or 2 steps it seems that it would be good. |
|||
05-07-2018, 08:08 AM
Post: #11
|
|||
|
|||
RE: WP34S - f SLV used with user selectable variables
(05-06-2018 11:36 PM)gomefun2 Wrote: If I want to store a single number such as 0.8175728566800069800087820069820087 for ASCII. do I have to do something like: Important note: always set DBLON or DBLOFF before (!) you store something in data registers. Since double precision requires more memory than standard precision the memory used for the data registers is interpreted differently when you recall or store something. Try it: in DBLOFF, store 0,009 in R00, change the mode and recall the number again: What was stored as 0,009 before is now returned as 2,139 E+16. You may even get a different result. The stack is not affected by this. Here the numbers stay the same even after a mode switch. (05-06-2018 11:36 PM)gomefun2 Wrote: // create the number 0.8175728566800069800087820069820087 for ASCII This of course requires a modified subroutine that implements this special way of encoding one or two characters. If this is required you could also switch to a method similar to ASCIIZ as used in some programming languages for storing strings: here a zero (Null-byte) marks the end of a string. This in turn means at least two digits for each variable. If you want to encode A, B, C1 and EPS this would be 6500660067490069808300. (05-06-2018 11:36 PM)gomefun2 Wrote: 00: LBL 99 // converts what is in the x-registry to variable names and stores the user input Which also means that there must be a unique relation between variable name and storage register. If the first character is used for the register number this would mean that E and EPS is stored in the same register... (05-06-2018 11:36 PM)gomefun2 Wrote: Since to put such a long number takes so many steps, is this really more efficient, than just using f-alpha-Enter? (for variable prompts?) if this long number could be entered in 1 or 2 steps it seems that it would be good. IMHO you should think about a maybe completely different approach. Don't get stuck with the idea of encoding variables names in numbers. Dieter |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)