The Museum of HP Calculators

HP Forum Archive 19

 HP 35s "Low footprint" Linear InterpolationMessage #1 Posted by Elliott W Jackson on 8 Feb 2009, 8:55 a.m. Hello, I went to college from '80-'84, and lived and died by my HP 41CV. I wrote dozens of programs for it as I progressed through my courses. I recently picked up a new HP 35s, and decided to convert one of my oldest, most-used HP41 programs to the 35 as a learning exercise mainly. The program just does simple linear interpolation. Suppose we have a table of data such as ```... X1 Y1 X2 Y2 ... ``` Given any value X, it simply estimates Y using linear interpolation. The equation to do that is brutally simple, it is just such a frequent need that it is a great candidate for a quickie program. As a further requirement however, I decided that I wanted to make it "low footprint," i.e. such that it only used the absolute minimum of the 26 A..Z named storage registers, and relied instead on the 800 indirect-addressed unnamed storage registers for any temporary storage requirements. I'm not sure how strong a need that is, frankly, but I thought it might be, to preserve the named registers for use as variables in equations, and allow those values to remain unmolested and untrampled-upon. That design decision did complicate things a bit, resulting in some muddy-looking code as the program plays games with the stack, but it's not too bad. Program Name: "L" (it lived for years as "LIP" in my HP41 calculators) Named storage registers used: I Un-named indirect addressed storage registers used: "n" through "n+3", where the value of "n" is set early in the program and can be easily changed if needed. Default = 10. ```L001 LBL L L002 10 Base register 'N' for storage L003 STO I N stored in I L004 SF 10 L005 X2,X1,X Prompt for X2 enter X1 enter X L006 CF 10 L007 STO(I) X stored in N L008 1 L009 STO+ I N+1 stored in I L010 RDN L011 RDN L012 STO(I) X1 stored in N+1 L013 1 L014 STO+ I N+2 stored in I L015 RDN L016 RDN L017 STO(I) X2 stored in N+2 L018 1 L019 STO+ I N+3 stored in I L020 SF 10 L021 Y2,Y1 Prompt for Y2 enter Y1 L022 CF 10 L024 STO(I) Y1 stored in N+3 L025 - (Y2-Y1) L026 1 L027 STO- I N+2 stored in I L028 RDN L029 RCL(I) X2 L030 1 L031 STO- I N+1 stored in I L032 RDN L033 RCL(I) X1 L034 - (X2-X1) L035 / (Y2-Y1)/(X2-X1) L036 RCL(I) X1 L037 1 L038 STO- I N stored in I L039 RDN L040 RCL(I) X L041 X<>Y L042 - (X-X1) L043 * (X-X1)*(Y2-Y1)/(X2-X1) L044 3 L045 STO+ I N+3 stored in I L046 RDN L047 RCL(I) Y1 L048 + (X-X1)*(Y2-Y1)/(X2-X1) + Y1 L049 RTN Y is left in X-register LN=166 CK=FC9A ``` As mentioned, the linear interpolation equation is trivial and straightforward and not really worthy of much discussion. The only thing possibly novel in this program is my attempt to make it "low footprint", and use the un-named storage registers as much as possible for temporary storage needs, rather than the named A..Z registers. That decision did complicate the code a bit, as I had to manipulate I in the middle of the "real math", which complicates the listing somewhat. Best, Elliott

 Re: HP 35s "Low footprint" Linear InterpolationMessage #2 Posted by Cliff V on 15 Feb 2009, 8:04 a.m.,in response to message #1 by Elliott W Jackson thanks for the program. step 23 is missing.

 Re: HP 35s "Low footprint" Linear InterpolationMessage #3 Posted by Elliott W Jackson on 15 Feb 2009, 8:39 p.m.,in response to message #2 by Cliff V Oops, thanks for noticing. It's actually not missing, my line numbers are just messed up. The LN and CK numbers are correct, and the program should end on line L048.

Go back to the main exhibit hall