Any RPN, No regs, line given 2 points
12-24-2017, 06:55 AM (This post was last modified: 12-26-2017 04:15 PM by Bill Duncan.)
Post: #1
 Bill Duncan Member Posts: 81 Joined: Jan 2016
Any RPN, No regs, line given 2 points
Thought this might be useful for others. Use it either by itself or as a subroutine. I often use it with the HP-29c, but should work with any. Given 2 points it returns the slope in X, intercept in Y which is convenient for keying in another X for a linear estimate (just enter X, * and +).

Code:
 LBL 0 x<>y RDN - LASTx x<>y RDN RDN x<>y - LASTx RDN x<>y / ENTER RDN * - x<>y RTN GTO 0

As a trivial example, moving data. Say, I'd copied 100gb of data an hour ago, 150gb are currently copied; how long will it take to copy all 1000gb?

-1 enter 100 enter 0 enter 150 gsb 0
1000 * +
12-24-2017, 10:56 PM
Post: #2
 Paul Dale Senior Member Posts: 1,672 Joined: Dec 2013
RE: Any RPN, No regs, line given 2 points
Code:
CLsigma Sigma+ Rv Rv Sigma+

Then use $$\hat{x}$$ or $$\hat{y}$$ to calculate interpolations and linear regression to get the slope and intercept.

Pauli
12-24-2017, 11:01 PM
Post: #3
 grsbanks Senior Member Posts: 1,198 Joined: Jan 2017
RE: Any RPN, No regs, line given 2 points
Yes, but the CLsigma and sigma+ functions use registers
12-24-2017, 11:10 PM
Post: #4
 Paul Dale Senior Member Posts: 1,672 Joined: Dec 2013
RE: Any RPN, No regs, line given 2 points
On the 42S REGS could be saved and restored I guess.

Pauli
12-24-2017, 11:10 PM
Post: #5
 Bill Duncan Member Posts: 81 Joined: Jan 2016
RE: Any RPN, No regs, line given 2 points
(12-24-2017 12:58 PM)Mike (Stgt) Wrote:  Special version for HP41
Code:
01·LBL "2PT" 02 ST- Z     03 RDN       04 ST- Z     05 RDN       06 /         07 *         08 ST- Y     09 X<> L     10 END
The 'canonical' way by calculating Delta x and Delta y instead of -Delta x and -Delta y would be two bytes longer. So it is up to you to enter point two first - if you mind. (Results are the same either way. )

Notes: to remember the sequence when entering the points just have in mind to match axis and register, x-value in register X, y-value in Y. So enter the y-value before the x-value for each point.
Output - slope in X, y-axis intercept in Y.

Ciao.....Mike

Very cool, yes, the extra stack operations available on the 41 are fabulous. I did want something I could use on various machines however, but thanks!
12-24-2017, 11:16 PM
Post: #6
 Bill Duncan Member Posts: 81 Joined: Jan 2016
RE: Any RPN, No regs, line given 2 points
(12-24-2017 11:10 PM)Paul Dale Wrote:  On the 42S REGS could be saved and restored I guess.

Pauli

Yes, linear regression could be used, but seemed like overkill using 6 registers. Also, not available on the hp-29c. I wanted something usable on any, and callable as a subroutine (with minimal side effects). But thanks!
12-25-2017, 03:42 PM
Post: #7
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Any RPN, No regs, line given 2 points
(12-24-2017 10:56 PM)Paul Dale Wrote:
Code:
CLsigma Sigma+ Rv Rv Sigma+

Of course the true 34s geek will use CPX X↔Y instead of R↓ R↓ here. ;-)

Dieter
12-25-2017, 04:00 PM
Post: #8
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Any RPN, No regs, line given 2 points
(12-24-2017 12:58 PM)Mike (Stgt) Wrote:  Special version for HP41

Yes, direct stack access on the 41 and 42 is nice.
But equations are even nicer – e.g. on the 35s:

Code:
(REGT-REGY)/(REGZ-REGX) REGZ-REGYxREGX X<>Y

(12-24-2017 12:58 PM)Mike (Stgt) Wrote:  Output - slope in X, y-axis intercept in Y.

Same here.

But all these are no universal solutions that will run on virtually any programmable HP RPN device, such as the solution in the initial post.

Dieter
12-26-2017, 12:46 AM
Post: #9
 Paul Dale Senior Member Posts: 1,672 Joined: Dec 2013
RE: Any RPN, No regs, line given 2 points
(12-25-2017 03:42 PM)Dieter Wrote:  Of course the true 34s geek will use CPX X↔Y instead of R↓ R↓ here. ;-)

CPX DROP would also work and handle the stack more nicely.

Pauli
 « Next Oldest | Next Newest »

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