Summation on HP 42S
|
09-23-2018, 10:03 PM
(This post was last modified: 09-23-2018 10:09 PM by Didier Lachieze.)
Post: #9
|
|||
|
|||
RE: Summation on HP 42S
(09-23-2018 06:51 PM)lrdheat Wrote: 100 in Y. No, I 'm using the stack registers X & Y, not variables "X" or "Y". So before calling the program you enter 100 (it's in the stack register X), at step 02 in the program 0 is enter in the stack register X and 100 is pushed to stack register Y which is then used by the two other instructions: RCL+ ST Y and DSE ST Y. (09-23-2018 09:25 PM)lrdheat Wrote: Neat stuff. For something a little more complex such as summation 1 through 100 of x^2 - 3*x, Here is a shorter way to do it. 100 XEQ SUM returns 323200 in ~11 seconds. Code: 01 LBL "SUM" At step 04 we have the current sum in X and the current value of x in Y, so we recall Y to calculate x-3. At step 07 we have x-3 in X, the current sum in Y and the current value of x in Z, so we recall and multiply Z to X to get x*(x-3) which is x^2 - 3*x. Then with + we get the updated sum in X and x moves down from Z to Y. For more complex functions it may not be possible to use only the stack so variables may be needed to store x and the sum but with the stack it's generally shorter and faster. Note: in your program you can remove the RCL "T" before the DSE, it's useless. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)