The Museum of HP Calculators

The Min-Max Line for the HP-41

This program is by Jean-Marc Baillard and is used here by permission.

This program is supplied without representation or warranty of any kind. Jean-Marc Baillard 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.

Overview:
 

Let be a set of n points ( x1 ; y1 ) ..... ( xn ; yn )
The min-max line:  y = m.x + p  minimizes the maximum "error"   h = abs( yi - m xi - p )
over the entire set of points.

The program uses the "exchange method" which is described for instance in
"Numerical Analysis" by Francis Scheid ( McGraw-Hill ) ISBN 07-055197-9

Data Registers:  Registers R00 thru R2n are used and all of them are to be initialized before executing MML

              R00 = n = the number of point
              R01 = x1  ;  R03 = x2  ;  .......... ; R2n-1 = xn    ( it's necessary to have x1 < x2 < x3 )
              R02 = y1  ;  R04 = y2  ;  .......... ;  R2n = yn

Flags and subroutines:  none.
 

The Program:

 The GTO 10 ( line 52 ) and GTO 01 ( lines 106 and 120 )
 are synthetic three-byte GTOs.
 Synthetic registers M N O P  can be replaced by any unused standard registers:
 for instance R41 R42 R43 R44  if  n < 21.

001  LBL "MML"
002  LBL 01
003  RCL 02
004  RCL 04
005  +
006  RCL 06
007  RCL 02
008  -
009  RCL 05
010  RCL 01
011  -
012  /
013  STO M
014  RCL 01
015  RCL 03
016  +
017  *
018  -
019  2
020  /
021  STO N
022  RCL 00
023  ST+ X
024  0
025  LBL 02
026  DSE Y
027  RCL IND Y
028  RCL M
029  *
030  RCL N
031  +
032  ISG T
033  CLX
034  RCL IND T
035  -
036  ABS
037  X<Y?
038  GTO 03
039  R^
040  STO O
041  X<>Y
042  LAST X
043  STO P
044  LBL 03
045  RDN
046  DSE Y
047  GTO 02
048  RCL O
049  PI
050  ST+ X
051  X>Y?
052  GTO 10
053  RCL IND O
054  ISG O
055  CLX
056  RCL P
057  LAST X
058  *
059  X<0?
060  GTO 06
061  CLX
062  RCL 03
063  X>Y?
064  GTO 05
065  RCL 06
066  X<> IND O
067  STO 06
068  DSE O
069  RCL 05
070  LBL 04
071  X<> IND O
072  STO 05
073  GTO 01
074  LBL 05
075  RCL 02
076  X<> IND O
077  STO 02
078  DSE O
079  RCL 01
080  GTO 09
081  LBL 06
082  CLX
083  RCL 05
084  X>Y?
085  GTO 07
086  RCL 06
087  X<> 04
088  X<> IND O
089  STO 06
090  DSE O
091  RCL 05
092  X<> 03
093  GTO 04
094  LBL 07
095  CLX
096  RCL 01
097  X>Y?
098  GTO 08
099  RCL 04
100  X<> IND O
101  STO 04
102  DSE O
103  RCL 03
104  X<> IND O
105  STO 03
106  GTO 01
107  LBL 08
108  RCL 02
109  X<> 04
110  X<> 06
111  X<> IND O
112  STO 02
113  DSE O
114  RCL 01
115  X<> 03
116  X<> 05
117  LBL 09
118  X<> IND O
119  STO 01
120  GTO 01
121  LBL 10
122  RCL N
123  RCL M
124  CLA
125  END

( 186 bytes / SIZE 2n+1 )
 
 
 
 
     STACK         INPUTS         OUTPUTS
           T              /         1 or 3 or 5
           Z              /               2p
           Y              /                 p
           X              /                 m
           L              /              ± h

 

An example:  Find the min-max line for the following data:
 
 
 
 xi   1   3   4   7  10  12  16  19  24  37  41  49  51  61
 yi   1   2   3   6   8   9  12  14  20  31  38  41  48  57

 

1- SIZE 029 ( or greater )
2- 14 STO 00 ( there are 14 points )
3-  1  STO 01  STO 02
      3  STO 03   2  STO 04
       ..............................
     61  STO 27   57 STO 28
4- XEQ "MML"  and  36 seconds later:       0.94
                                                    RDN      -2.5              the min-max line is  y = 0.94 x - 2.5
   the maximum error is  h = 2.56
 ( the L-register contains -2.56 )

-Note that the least squares line is  0.9275 x - 1.4785 in this example.

Go back to the HP-41 software library
Go back to the general software library
Go back to the main exhibit hall