Post Reply 
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
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 * +
Answer, 17 more hours..
Find all posts by this user
Quote this message in a reply
12-24-2017, 10:56 PM
Post: #2
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
Find all posts by this user
Quote this message in a reply
12-24-2017, 11:01 PM
Post: #3
RE: Any RPN, No regs, line given 2 points
Yes, but the CLsigma and sigma+ functions use registers Smile
Find all posts by this user
Quote this message in a reply
12-24-2017, 11:10 PM
Post: #4
RE: Any RPN, No regs, line given 2 points
On the 42S REGS could be saved and restored I guess.


Pauli
Find all posts by this user
Quote this message in a reply
12-24-2017, 11:10 PM
Post: #5
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. Wink )

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! Wink
Find all posts by this user
Quote this message in a reply
12-24-2017, 11:16 PM
Post: #6
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!
Find all posts by this user
Quote this message in a reply
12-25-2017, 03:42 PM
Post: #7
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
Find all posts by this user
Quote this message in a reply
12-25-2017, 04:00 PM
Post: #8
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
Find all posts by this user
Quote this message in a reply
12-26-2017, 12:46 AM
Post: #9
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
Find all posts by this user
Quote this message in a reply
Post Reply 




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