Calculator software for curve fit for HP41. Computes a curve to a set of data points. (linear, exponential, logarithmic and power). The code originates from the PPC ROM Module released by the international group People Programming Computers on December 1981 [1,2]. That in turn was based on Gary Tenzer’s curve fit program published in PPC Journal.\(\)
name  formula  restriction 

linear  \(y=bx + a\)  
exponential  \(y=ae^{bx}\)  for \(a>0\) 
logarithmic  \(y=b\ln{x}+1\)  
power  \(y=ax^{b}\)  for \(a>0\) 
The program will compute the coefficients a and b for the curve types as well as compute the coefficient of determination (r^{2}) which is a measure of the goodness of fit. Once a set of data has been fit to a given curve type, a prediction may be made for the yvalue given a new xvalue, or a prediction may be made for the xvalue given a new yvalue.
Instructions
The functions map to the top row on the USER keyboard. These same functions are referenced in the examples by enclosing them in a blue box.
The key mappings are shown in the table below.
USER  keyboard  description  usage 

∑+  ∑+  Add a data point  x ENTER y ∑+ 
∑  ∑  Delete a data point  x ENTER y ∑+ 
SOLVEj  1/x  Solve type j  j SOLVEj 
y^  √x  Predict y value  x y^ 
x^  LOG  Predict x value  y x^ 
SOLVE  LN  Solve best type  
INIT  e^{x}  Initialize 
Operation
 GTO “CV”
 SIZE 027
 USER mode
 INIT, the display will show 1.
 key in the data pairs as x ENTER y and push ∑+. The display will stop with the count of the number of the next data pair. This feature makes it possible to enter only the yvalues when the xvalues are consecutive integers starting at 1. In this case the display provides the xvalues which need to be entered. If an improper data pair has just been input with the ∑+ key, then immediately press R/S will delete the pair. Otherwise an improper or undesired data pair can be deleted by reentering both x and y and pressing ∑.
 repeat step until all data pairs are entered.
 If any xvalues are negative or zero, then only types 1 and 2 are feasible curves. If any yvalues are negative or zero, then only types 1 and 3 are feasible curves. If in any data pair both and x and y are negative or zero, the type 1 is the only feasible curve. The a coefficient must be positive for curve type 2 and 4.
 Select the desired curve type. Once the curve type is selected, the HP41 should not be interrupted.

To fit a particular curve type, key in the number 14 for that type and press SOLVEj. The stack returns with:
Stack usage stack register description Z R10 R^{2} Y R09 a coefficient X R08 b coefficient  The closer R^{2} is to one of the extremes (1 or 1), the better the fit. The sign indicates whether the data is positively or negatively skewed. Note that this step may be repeated any number of times of any of the four curve types.

If all data data input is positive, then pressing SOLVE will automatically choose the curve of best fit according to the curve type with largest absolute value of r^{2}. In this case the stack returns with:
Stack usage stack register description Z R10 R^{2} Z R09 a coefficient Y R08 b coefficient X R07 j = best curve type 
Predictions for new x or y values may be made only after the previous step has been completed. Predictions for new values are based on curve type (encoded in flags F08 and F09).
 To predict y given x, key in x and press y^
 To predict x given y, key in y and press x^
 New data may be added or deleted at any time via the ∑+ and ∑ keys. However the “solve” must be preformed after updating the data before any new predictions can be made. The parameters a and b automatically destroyed after input of new data.
Examples
We reuse the examples from the PPC ROM User Manual. [hp41.com]
Straight line
Find the straight line which best fits the data set shown below, and predict y when \(x=20\) and predict \(x\) when \(y=25\).
Minimum size is SIZE 25
.
key strokes  display 

GTO “CV”  
SIZE 027  
USER  
INIT  1.0000 
1.1 ENTER 5.2 ∑+  2.0000 
4.5 ENTER 12.6 ∑+  3.0000 
8 ENTER 20 ∑+  4.0000 
10 ENTER 23 ∑+  5.0000 
15.6 ENTER 34  6.0000 
1 SOLVEj  1.9720 
After solving for linear (type 1), the values for \(a\), \(b\) and \(R^2\) are on the stack. We find:
To determine the points along that line:
key strokes  display 

20 y^  42.94009811 
25 x^  10.90280649 
Linear or exponential curve
The data shown below fits either a linear or exponential curve. Determine which is more appropriate.
Again, to solve this, we use the CV
program.
key strokes  display  description 

INIT  1.0000  
2 ENTER 12 ∑+  2.0000  
1 CHS ENTER 2 ∑+  3.0000  
3 ENTER 17 ∑+  4.0000  
5 ENTER 23 ∑+  5.0000  
1 SOLVEj  3.5467  linear, b coefficient 
R  5.5200  linear, a coefficient 
R  0.9976  linear, R^{2} 
2 SOLVEj  3.5467  exponential, b coefficient 
R  3.8262  exponential, a coefficient 
R  0.9586  exponential, R^{2} 
Choosing the best \(R^2\), we find a linear fit is more appropriate.
Predict \(y\) when \(x=10\). Since we just finished the exponential fit, the exponential parameters are still in the machine, and hence we must go back and solve for linear to predict \(y\) for \(x=10\).
key strokes  display  description 

1 SOLVEj  3.5467  
10 CHS y^  29.9467 
Add the additional data points shown below and solve the same problem.
Note that the display should show 6 after entering the first new data pair. We try a linear and exponential fit.
key strokes  display  description 

4 CHS ENTER 0.713 ∑+  6.0000  
2.5 ENTER 10.93 ∑+  7.0000  
6 ENTER 47.53 ∑+  8.0000  
10 ENTER 254.95 ∑+  9.0000  
1 SOLVEj  15.3315  linear, b coefficient 
R  0.9790  linear, a coefficient 
R  0.7657  linear, R^{2} 
2 SOLVEj  0.4199  exponential, b coefficient 
R  3.8256  exponential, a coefficient 
R  0.9936  exponential, R^{2} 
Now choosing the best \(R^2\), we see that the new data reflects a change in the curve type.
Since the exponential parameters are still in the machine, we can predict \(y\) for \(x=10\) as
key strokes  display 

10 CHS y^  0.0574 
Best curve
Fit the best curve to the data points shown below.
In this example the \(x\)coordinates start counting from \(1\) and are consecutive integers. So we need only input the ycoordinates, but they must be in the proper order. The count in the display will serve as the xcoordinates.
key strokes  display 

INIT  1.0000 
2 ∑+  2.0000 
2.828 ∑+  3.0000 
3.464 ∑+  4.0000 
4 ∑+  5.0000 
4.472 ∑+  6.0000 
4.899 ∑+  7.0000 
5.292 ∑+  8.0000 
5.657 ∑+  9.0000 
6 ∑+  10.0000 
SOLVE  4.0000 
We could use the best fit function because all the values were positive. After solving, the stack represents j, b, a and r^{2}. The value j=4 indicates a power curve. Rounded to 2 decimals, this is
Source code

Requires XFunctions module on the HP41cv, and a minimum
SIZE 25
.  Available as source code, raw code for the V41 emulator and bar code for the HP Wand (HP82153A)
 Size 321 Bytes, 3 magnetic tracks (321/112=2.866)
Listing
Available through the repository
References
[1]  CV – Curve Fit Gary Tenzer, Keith Jarret and John Kennedy, August 1981 PPC User Manual, page 110111 

[2]  BC – Block Clear John Kennedy, August 1981 PPC User Manual, page 5051 