[comp.sys.handhelds] Interpolation Program

paul+@andrew.cmu.edu (Paul J. Dujmich) (11/12/90)

Here is a little ditty I wrote this term for Thermodynamics.
It does interpolation between 2 numbers (like 2 values from the steam
tables). The program looks at the number of decimal places in the values
you enter, and displays the interpolated result with that number of
decimal places. The 48 is returned to your decimal place setting upon
exit from the program. It has proved to be a real time saver when a lot
of interpolation must be performed ie thermodynamics, fudging fake data
points in lab etc.

Paul J. Dujmich
Electrical/Computer Engineering Dept
Carnegie Mellon University
-------------------------------------------------------------------------------
%%HP: T(3)A(R)F(.);
@ PROGRAM NAME:       intp
@ DATE:               9-18-90  Paul Dujmich (pauld(at sign)fs1.ece.cmu.edu)
@ PURPOSE:            Does Interpolation Between two values
@ ARGUMENTS:          Level 5: low reference
@                     Level 4: value at low reference
@                     Level 3: high reference
@                     Level 2: value at high reference
@                     Level 1: desired point between low reference and
@                              high reference.
@
@      Example:
@                 at 100 value = 10
@                 at 200 value = 8.8
@
@                 Find the value at 155.67
@
@                 Enter to stack:  100
@                                  10
@                                  200
@                                  8.8
@                                  155.67
@
@                 Press 'INTP'  (The Interpolated value of 9.3 is displayed)
@ (Store program in a variable called 'INTP')
@ Note: The interpolated value displayed will have the same number of
@       decimal places as the two values entered.



\<< 0 0 0 \-> lr lv hr hv p dp ndp tst
  \<< -45 FS? 'dp' STO+          @Test flags -45 to -48 to determine
      -46 FS? 2 * 'dp' STO+      @how many decimal places are selected
      -47 FS? 4 * 'dp' STO+      @upon entry into program
      -48 FS? 8 * 'dp' STO+      @save in dp

     @ determine which value (lv or hv) has biggest fractional part
     @ the one with biggest fractional part is used to determine the
     @ number of decimal places to set the display to.

      IF 'FP(lv) > FP(hv)' THEN lv 'tst' STO
         ELSE hv 'tst' STO
      END


    @***** do this if exponent is negative ****************************
    IF 'XPON(tst)<0'              @if low value has a negative exponent
        THEN tst XPON NEG         @imvert it and put it in ndp
        'ndp' STO+
        tst MANT FP               @get fraction part of Matissa

        ELSE                     @do this for positive exponents
            tst MANT FP           @get fractional part of mantissa
            tst XPON ALOG *       @multiply it by 10^(exponent of lv)
        END


    @*** do this for both positive and negative exponents ********
    WHILE  FP DUP 0 >            @ shift left 1 decimal place
          REPEAT .1 /            @add 1 to decimal place count
          1 'ndp' STO+
          END
DROP                             @set decimal places for display
ndp FIX

p lr -                           @low reference - desired point
hr lr - /                        @high reference - low reference, get factor
    IF 'hv>lv'                   @ if high value > low value
         THEN hv lv - *          @get difference and multiply by factor
         lv +                    @add it to low value
         'lv' STO                @save interpolated value
         "Int Val = "
         lv +
         CLLCD 1 DISP 7 FREEZE   @display it on screen

    ELSE lv hv - *               @low value - high value *factor
         NEG lv +                @make it minus, multiply with factor
         'lv' STO                @save interpolated value
         "Int Val = "
         lv +
         CLLCD 1 DISP 7 FREEZE   @display it on screen
         END
dp FIX                           @restore old decimal point setting
  \>>
\>>