The Museum of HP Calculators


Equation of Line Given Two Points

By bill duncan

This program is supplied without representation or warranty of any kind. The author and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.

Description

I often need to interpolate on a straight line given two points. This is easy on calculators with linear regression built-in such as the HP-27 or HP-15C. Using Linear regression programs available for other machines such as the HP-29C or HP-41C is possible, but overkill for the 90% of the time where I am just interpolating using two known points.

This is a very simple routine which does not use any registers. It is called with the two points on the stack and returns with the coefficients on the stack. Thus it is callable as a subroutine as well.

 Input:         Output:
   T = Y2         Y = A
   Z = X2         X = B
   Y = Y1   
   X = X1       Where:  A = y intercept, B = slope

When the routine finishes, you can calculate a new "Y" given "X" by keying in a value for X and pressing:   ×  +

Note

This routine also works well with the HP-41C and probably most other RPN calculators.

Example

The temperature and winds aloft are given for every 3000 feet. You wish to fly at an altitude of 5000ft and are given temperatures of 10C at 3000ft and 4C at 6000 ft. At 3000ft the wind is 15 knots at 200 degrees. At 6000ft the wind is 12 knots at 215 degrees. What is the likely temperature and winds at the height you wish to fly? (Very simple for illustration.)


   10 ENTER↑  3000 ENTER↑  4 ENTER↑  6000 GSB 3
   5000 × +
   Answer displayed is:  6 degrees

   15 ENTER↑  3000 ENTER↑  12 ENTER↑  6000 GSB 3
   5000 × +
   Answer displayed is:  13 knots

   200 ENTER↑  3000 ENTER↑  215 ENTER↑  6000 GSB 3
   5000 × +
   Answer displayed is:  210 degrees

HP-29C Listing

Short and sweet. It's redundant on the HP-15C, but I find it useful on both the HP-29C and the HP-41. Could probably shorten it for the HP-41C, but why bother? Can anyone shave anything off for the HP-29C?


01   15 13 03   LBL 3
02         21   x⇔y
03         22   R↓
04         41   -
05      14 73   LASTx
06         21   x⇔y
07         22   R↓
08         22   R↓
09         21   x⇔y
10         41   -
11      14 73   LASTx
12         22   R↓
13         21   x⇔y
14         71   ÷
15         31   ENTER↑
16         22   R↓
17         61   ×
18         41   -
19         21   x⇔y
20      15 12   RTN
21      13 03   GTO 3


$Id: line.html,v 1.5 2000/07/05 16:45:53 bduncan Exp $

Go back to the software library
Go back to the main exhibit hall