|HP 35s "Low footprint" Linear Interpolation|
Message #1 Posted by Elliott W Jackson on 8 Feb 2009, 8:55 a.m.
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
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
L009 STO+ I N+1 stored in I
L012 STO(I) X1 stored in N+1
L014 STO+ I N+2 stored in I
L017 STO(I) X2 stored in N+2
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)
L027 STO- I N+2 stored in I
L029 RCL(I) X2
L031 STO- I N+1 stored in I
L033 RCL(I) X1
L034 - (X2-X1)
L035 / (Y2-Y1)/(X2-X1)
L036 RCL(I) X1
L038 STO- I N stored in I
L040 RCL(I) X
L042 - (X-X1)
L043 * (X-X1)*(Y2-Y1)/(X2-X1)
L045 STO+ I N+3 stored in I
L047 RCL(I) Y1
L048 + (X-X1)*(Y2-Y1)/(X2-X1) + Y1
L049 RTN Y is left in X-register
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.