Post Reply 
Solve w/ HP-41 Formula Eval Module
07-17-2017, 04:39 PM (This post was last modified: 07-17-2017 04:46 PM by Ángel Martin.)
Post: #1
Solve w/ HP-41 Formula Eval Module
Hardly a new invention, yet the Secant method acquires a new and simplified dimension on the HP-41 using the Folmula_Eval module. Welcome to the new FOCAL, or the FOCAL$ as somebody suggested it could be called.

Here's the code. Use initial guesses in Y, X with the formula in ALPHA
Set flag 10 if you want to see the succesive iterations .

Code:
01  LBL "SV$"
02  STO$ (00)
03  LBL 00
04  EVALZ
05  X<>Y
06  EVALT
07  "Y-Z*(Y-X)/(Z-T)"
08  EVAL$
09  FS? 10
10  VIEW X(3)
11  RCL$  (00)
12  X#Y?
13  GTO 00
14  END

It uses R00-R03 to store the formula expression.

As listed it uses all 9 decimal places to determine the equal condition. You can change it using RND statements as usual - in case the convergence fails for oscillations. Many other refinements are also possible, but I thought you'd like to see the "sketch" version first.

Doesn't get any shorter or easier, as any BASIC programmer knows ;-)
Find all posts by this user
Quote this message in a reply
07-17-2017, 06:19 PM
Post: #2
RE: Solve w/ HP-41 Formula Eval Module
What values are in Z and T the first time this is executed?

If formula is in ALPHA and guesses in X and Y, then I don't see anything that pushes X and Y into Z/T the first time through the loop. Doesn't that mean you could have an error based on bad data in Z/T ?

Seems like it needs a DUP2 command of some sort to DUP XY into ZT ? That might prove useful for more than just this instance.

And sorry :-) What does VIEW X(3) mean/do ? VIEW X is clear, but what is the (3) in there do ?
Find all posts by this user
Quote this message in a reply
07-18-2017, 04:41 AM (This post was last modified: 07-18-2017 05:03 AM by Ángel Martin.)
Post: #3
RE: Solve w/ HP-41 Formula Eval Module
(07-17-2017 06:19 PM)Gene Wrote:  What values are in Z and T the first time this is executed?

If formula is in ALPHA and guesses in X and Y, then I don't see anything that pushes X and Y into Z/T the first time through the loop. Doesn't that mean you could have an error based on bad data in Z/T ?

EVALZ puts the result in Z, and EVALT puts the result in T. All is intended, no random values but f(xn-1) and f(xn),

(07-17-2017 06:19 PM)Gene Wrote:  Seems like it needs a DUP2 command of some sort to DUP XY into ZT ? That might prove useful for more than just this instance.

No need for it as per above.


(07-17-2017 06:19 PM)Gene Wrote:  And sorry :-) What does VIEW X(3) mean/do ? VIEW X is clear, but what is the (3) in there do ?

Yes, the "X" register is the same as the X(3) register. The number refers to its absolute address. This notation is helpful for additional clarity, like for instance to differentiate M(5), N(6) from the CPU M, N registers, etc.
Find all posts by this user
Quote this message in a reply
07-18-2017, 02:21 PM
Post: #4
RE: Solve w/ HP-41 Formula Eval Module
Ah, sorry, now I see it. Question might help someone else who does not.

EVALT will evaluate the formula in ALPHA "X+Y" or "X+T/Y" or whatever, using the values in the indicated stack registers and overwrite the value computed into the T register. Same with EVALZ etc. but in this case, the object is to find the root of X with guesses in X and Y.

Therefore, EVALZ will take X and compute the function value, followed by X<>Y EVALT which will compute the function value using the second guess originally in Y.

My confusion was thinking EVALZ would take the value of Z as the "X" for the evaluation and store the result in Z. That's not correct of course.
Find all posts by this user
Quote this message in a reply
07-22-2017, 09:37 PM
Post: #5
RE: Solve w/ HP-41 Formula Eval Module
(07-18-2017 02:21 PM)Gene Wrote:  Ah, sorry, now I see it. Question might help someone else who does not.

EVALT will evaluate the formula in ALPHA "X+Y" or "X+T/Y" or whatever, using the values in the indicated stack registers and overwrite the value computed into the T register. Same with EVALZ etc. but in this case, the object is to find the root of X with guesses in X and Y.

Therefore, EVALZ will take X and compute the function value, followed by X<>Y EVALT which will compute the function value using the second guess originally in Y.

My confusion was thinking EVALZ would take the value of Z as the "X" for the evaluation and store the result in Z. That's not correct of course.

What Ángel and I tried to do with the EVALx series of functions was to insure that only the intended stack register (and LastX) was modified with the results of the formula in Alpha. Hence, EVAL$ touches X and L only, EVALY touches Y and L only, EVALZ touches Z and L only, EVALT touches T and L only, and EVALL touches only L (with EVALL having no LastX capability, of course).

We get away with that because all the partial calculations are pushed/popped from a special buffer (#6) as well as other important formula info. So this yields a lot of power to the user, allowing them to use the stack the way they want to. This action only occurs at the very end of the formula evaluation phase, and that means you have 5 "variables" to use in the stack (X, Y, Z, T, and L) and 5 "constants" to use in buffer 7 (a, b, c, d, and e) before the stack is modified by the final phase of the desired EVALx function.

About the only negative to all this is execution time (this is due to formula interpretation), but with positive tradeoffs of not having to create a FOCAL program to evaluate a formula, and controlled use of the stack. Now for REALLY complicated formulas, FOCAL is there ready to execute the EVALx statements, as shown with the SV$ example at the beginning of this thread.

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




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