Improving the solver experience on the 41C

02162016, 03:41 AM
Post: #1




Improving the solver experience on the 41C
One of the features I like about latermodel HP calculators is the use of named variables and the ability to solve for any one of the variables in an equation. The solver function available in the Advantage module is decent enough from a functional standpoint, but one generally needs to write multiple RPN functions for the same equation, depending on the variable being solved for. I came across this program which stores the values of all variables in registers and uses indirect register addressing to update the unknown variable during root finding. I extended this technique to make things more userfriendly. Here is the program I came up with:
Code: 01◆LBL "SLV" The SLV program has two requirements: the Advantage module SOLVE function (or another root finder) and an RPN function that you write to evaluate your equation. To illustrate how the equation function is written, let's use a simple example from classical mechanics: x=v0*t+(1/2)*a*t^2. The RPN function for this equation is written in the following manner: Code: 01◆LBL "MOT" The function starts with a global label. Following that, a check of flag 05 is performed, which informs the function whether it's being called during root finding or for generating a user prompt. When evaluating the function during root finding, SLV clears flag 05, and the current estimate for the unknown variable is stored indirectly into the appropriate register in line 04. Lines 0516 evaluate the function by recalling the values of the variables and performing the arithmetic. This is where you would enter the RPN steps for your equation f(x1,x2,...)=0. You can use up to 5 variables, and it's up to you to decide which variable goes into which register, 0105. The alpha string following LBL 00 provides a user prompt and can be designed so that the variable name appears above the toprow key corresponding to the register (key "A" for 01, etc.). Here are the instructions for running the SLV program:
I like this technique because the equation and its prompting string are stored as a single function. While it takes a moment to plan out register usage, once you've created the function, you don't need to remember which register is which any more. I'd be pleased to hear any suggestions for improvement. It seems like something similar should have been written in the past, but I was unable to find anything. The AECROM has a nice interface for entering an equation and generating a program from it, but you have to decide ahead of time which variable you're going to solve for. David Brunell Houston, Texas 

02162016, 10:19 AM
(This post was last modified: 02162016 10:42 AM by Ángel Martin.)
Post: #2




RE: Improving the solver experience on the 41C
Very nice improvement on Stefan Vorkoetter's program; here's my proposal using the data entry flag F22 to rewrite your SLV routine as follows:
Code:
Only 45 steps are needed, and a bunch of bytes are saved as well. Also no need to use [SHIFT] to determine the unknown  so it's standard with the other solvers, like the TMV$. So you'll enter all the knowns and then press the softkey corresponding to the unknown to trigger the SOLVE process. BTW I've used FROOT from the SandMath instead.. Writing an MCODE equation solver has always lured me but I guess I don't know enough to tackle the job. BTW  There's one ROM image I prepared a while ago that deals with this very same subject; it's called "Interchangeable Solutions" and contains the FOCAL programs of the same name available at TOS? (written by Humbert Hans Suarez, from the User's Program Library Europe, REF#01475C). It's a tad more complex but quite flexible in the number of variables and governing equations. 

02162016, 07:44 PM
Post: #3




RE: Improving the solver experience on the 41C
Thanks, Ángel. That is a nice simplification and space savings. I'll check out the Interchangeable Solutions ROM as well. It's not on TOS, but I found it on Geir's site.
It's too bad the 41C doesn't have a 2line display as that would improve the user interface. However, I happen to have a 2line OLED display that fits perfectly where the existing LCD sits, and a small ARM processor board running nonpareil... David Brunell Houston, Texas 

02172016, 06:25 AM
(This post was last modified: 02172016 03:52 PM by Ángel Martin.)
Post: #4




RE: Improving the solver experience on the 41C
Last night I resubmitted to TOS the Interchangeable Solutions Module and UPLE program documentation (needed for it to be useful); should be available in a few days if all goes well.


02202016, 04:42 PM
(This post was last modified: 02202016 04:58 PM by Jeff_Kearns.)
Post: #5




RE: Improving the solver experience on the 41C
(02162016 03:41 AM)quantalume Wrote: One of the features I like about latermodel HP calculators is the use of named variables and the ability to solve for any one of the variables in an equation. The solver function available in the Advantage module is decent enough from a functional standpoint, but one generally needs to write multiple RPN functions for the same equation, depending on the variable being solved for. Karl Schneider wrote an excellent article on how SOLVE and INTEG work in HP's RPNbased models. In it, he addresses the issue you raised about 'generally' needing to write multiple RPN functions in order to solve for different variables in a multivariable equation by invoking a multipleinput, singleoutput (MISO) procedure. I have found this technique particularly useful in the HP15C  especially for the TVM equation with 6 variables  and the use of the indirect storage register (e.g IND 00 in the HP41C) allows for solving any variable. While your program certainly has some interesting features in that it creates a menu of variables, why go to all the trouble to write a new solver routine rather than use the existing Advantage Pac program, if you have it already? Can the menu feature be combined with the ADV routine? I get the impression that Stefan Vorkoetter's approach was initially based on his HP19C (29C) solver routine and was ported to the HP41 because he didn't have an Advantage Pac. Please correct me if I am mistaken. Jeff Kearns 

02202016, 05:08 PM
Post: #6




RE: Improving the solver experience on the 41C
(02202016 04:42 PM)Jeff_Kearns Wrote: While your program certainly has some interesting features in that it creates a menu of variables, why go to all the trouble to write a new solver routine rather than use the existing Advantage Pac program, if you have it already? Can the menu feature be combined with the ADV routine? That's exactly what Dave's program does  not a rewrite but a "shell" around SOLVE. My version uses a shorter shell, and is around FROOT instead (both are equivalent). 

02202016, 05:59 PM
Post: #7




RE: Improving the solver experience on the 41C
(02202016 05:08 PM)Ángel Martin Wrote: Very nice improvement on Stefan Vorkoetter's program... Ángel: Thanks for the clarification. I look forward trying this out. Jeff 

« Next Oldest  Next Newest »

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