HP 35s "Low footprint" Linear Interpolation Message #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, mostused 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 indirectaddressed 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 untrampledupon. That design decision did complicate things a bit, resulting in some muddylooking 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
Unnamed 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  (Y2Y1)
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  (X2X1)
L035 / (Y2Y1)/(X2X1)
L036 RCL(I) X1
L037 1
L038 STO I N stored in I
L039 RDN
L040 RCL(I) X
L041 X<>Y
L042  (XX1)
L043 * (XX1)*(Y2Y1)/(X2X1)
L044 3
L045 STO+ I N+3 stored in I
L046 RDN
L047 RCL(I) Y1
L048 + (XX1)*(Y2Y1)/(X2X1) + Y1
L049 RTN Y is left in Xregister
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 unnamed 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
