This program is Copyright © 1975 by HewlettPackard and is used here by permission. This program was originally published in "HP25 Applications Programs" as four separate programs. These were generalized into four versions of one program and reorganized by Lawrence Leinweber.
This program is supplied without representation or warranty of any kind. HewlettPackard Company, Mr. Leinweber, 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.
When investigating the relationship between two variables in the real world, it is a reasonable first step to make experimental observations of the system to gather paired values of the variables, (x, y). The investigator might then ask the question: What mathematical formula best describes the relationship between the variables x and y? His first guess will often be that the relationship is linear, i.e., that the form of the equation is y = a_{1}x + a_{0}, where a_{1} and a_{0} are constants. The purpose of this program is to find the constants a_{1} and a_{0}, which give the closest agreement between the experimental data and the equation y = a_{1}x + a_{0}. The technique used is linear regression by the method of least squares.
The user must input the paired values of data he has gathered, (x_{i}, y_{i}), i = 1, ..., n. When all data pairs have been input, the regression constants a_{1} and a_{0} may be calculated. A third value may also be found, the coefficient of determination, r^{2}. The value of r^{2} will lie between 0 and 1 and will indicate how closely the equation fits the experimental data: the closer r^{2} is to 1, the better the fit.
y = a_{1}x + a_{0}
All summations below are performed for i = 1, ..., n.
Regression constants:
a_{1} = (xy  x y ÷ n) ÷ (x^{2}  (x)^{2} ÷ n)
a_{0} = y ÷ n  a_{1}x ÷ n
Coefficient of determination:
r^{2} = [xy  x y ÷ n]^{2} ÷ [x^{2}  (x)^{2} ÷ n] ÷ [y^{2}  (y)^{2} ÷ n]
Besides the linear curve fit, HewlettPackard included three similar programs for exponential, logarithmic, and power curve fits. The minor differences between these versions are noted in the text below.
* The logarithms of x, y and a_{0} are introduced here as x*, y* and a_{0}*, then the distinction is dropped because it unnecessarily complicates the instructions below. Technically, the equations in the overview section above refer to the ordinary variables, whereas the data references in the sections below refer to the logarithms as described in this section.
This version fits a linear curve
y = a_{1}x + a_{0}
to a set of data points {(x_{i}, y_{i}), i =1, ..., n}.
Let a_{0}* = ln a_{0} (a_{0}* > 0) and y* = ln y (y* > 0). Substituting into the linear equation y = a_{1}x + a_{0} above, gives ln y* = a_{1}x + ln a_{0}* or y* = a_{0}* e^{(a1x)}.
This version fits an exponential curve
y = a_{0} e^{(a1x)} (a_{0} > 0)
to a set of data points {(x_{i}, y_{i}), i =1, ..., n}, where y_{i} > 0.
Let x* = ln x (x* > 0). Substituting into the linear equation y = a_{1}x + a_{0} above, gives y = a_{1} ln x* + a_{0}.
This version fits a logarithmic curve
y = a_{0} + a_{1} ln x
to a set of data points {(x_{i}, y_{i}), i =1, ..., n}, where x_{i} > 0.
This is a combination of both the exponential and logarithmic curve fits. Substituting a_{0}*, y* and x* into the linear equation y = a_{1}x + a_{0} above, gives ln y* = a_{1}ln x* + ln a_{0}* or y* = a_{0}* x*^{(a1)}.
This version fits a power curve
y = a_{0} x^{(a1)} (a_{0} > 0)
to a set of data points {(x_{i}, y_{i}), i =1, ..., n}, where x_{i} > 0, y_{i} > 0.
Step 
Instructions 
Input Data/Units 
Keys 
Output Data/Units 
1 
Key in program 

2 
Initialize 
f REG f PRGM 

3 
Perform for i = 1, ..., n: 

Input xvalue and yvalue 
x_{i} 
ENTER 

y_{i} 
R/S 
i 

4 
Compute regression constants and coefficient of determination 
GTO 10 R/S 
a_{0} 

roll dn 
a_{1} 

roll dn 
r^{2} 

5 
To calculate a projected yvalue, input the xvalue 
x 
R/S 
y (estimate) 
6 
Perform step 5 as many times as desired 

7 
For a new case, go to step 2 
An eccentric professor of numerical analysis wakes up one morning and feels feverish. A search through his medicine cabinet reveals one oral thermometer which, unfortunately, is in degrees centigrade, a scale he is not familiar with. As he stares disconsolately out his window, he spies the outdoor thermometer affixed to the windowframe. This thermometer, however, will not fit comfortably into his mouth. Still, with some ingenuity....
The professor suspects that the relationship is F = a_{1}C + a_{0}. If he can get a few data pairs for F and C, he can run a linear regression program to find a_{1} and a_{0}, then convert any reading in °C to °F through the equations. So tossing both thermometers into a sink of lukewarm water, he reads the following pairs of temperatures as the water cools:
C 
40.5 
38.6 
37.9 
36.2 
35.1 
34.6 
F 
104.5 
102 
100 
97.5 
95.5 
94 
If the relationship is indeed F = a_{1}C + a_{0}, what are the values for a_{1} and a_{0}? What is the coefficient of determination?
Keys 
Output 
f PRGM f REG 40.5 ENTER 104.5 R/S 
1.00 
38.6 ENTER 102 R/S 
2.00 
37.9 ENTER 100 R/S 
3.00 
36.2 ENTER 97.5 R/S 
4.00 
35.1 ENTER 95.5 R/S 
5.00 
34.6 ENTER 94 R/S 
6.00 
GTO 10 R/S 
33.53 
roll dn 
1.76 
roll dn 
0.99 
Thus, by the data above, F = 1.76 C + 33.53, with r^{2} = 0.99. (The real equation, of course, is F = 1.8C + 32.)
Suppose the professor puts the centigrade thermometer in his mouth and finds he has a temperature of 37°C. Should he be worried?
37 R/S 
98.65°F 
It looks like he is safe.
x_{i} 
.72 
1.31 
1.95 
2.58 
3.14 
y_{i} 
2.16 
1.61 
1.16 
.85 
0.5 
a_{0} = 3.45, a_{1} = 0.58
y = 3.45 e^{0.58x}
r^{2} = 0.98
For x = 1.5, y (est.) = 1.44
x_{i} 
3 
4 
6 
10 
12 
y_{i} 
1.5 
9.3 
23.4 
45.8 
60.1 
a_{0} = 47.02, a_{1} = 41.39
y = 47.02 + 41.39 ln x
r^{2} = 0.98
For x = 8, y (est.) = 39.06
For x = 14.5, y (est.) = 63.67
x_{i} 
10 
12 
15 
17 
20 
22 
25 
27 
30 
32 
35 
y_{i} 
0.95 
1.05 
1.25 
1.41 
1.73 
2.00 
2.53 
2.98 
3.85 
4.59 
6.02 
a_{0} = .03, a_{1} = 1.46
y = .03 x^{1.46}
r^{2} = 0.94
For x = 18, y (est.) = 1.76
For x = 23, y (est.) = 2.52
LINE CODE KEYS COMMENTS 00 /01\ /15 74\ /g NOP\ /Linear or logarithmic curve fit \01/ \14 07/ \f ln / \Exponential or power curve fit 02 31 ENTER Steps 19 for summation 03 15 02 g x^{2} 04 23 51 02 STO + 2 sum y^{2} 05 22 roll dn 06 21 x<>y /07\ /15 74\ /g NOP\ /Linear or exponential curve fit \07/ \14 07/ \f ln / \Logarithmic or power curve fit 08 25 sum+ n, sum y, sum xy, sum x^{2}, sum x 09 13 00 GTO 00 10 24 05 RCL 5 11 14 21 f mean x 12 24 04 RCL 4 13 61 × 14 41  C = sum xy  (sum x sum y / n) 15 24 06 RCL 6 (C goes on a magic carpet ride) 16 24 07 RCL 7 17 14 21 f mean x (C at top of stack) 18 61 × (C is duplicated as stack falls) 19 41  D = sum x^{2}  [(sum x)^{2} / n] 20 71 ÷ a_{1} = C / D 21 23 01 STO 1 22 61 × a_{1} * C (handy extra copy of C) 23 24 02 RCL 2 24 24 04 RCL 4 25 15 02 g x^{2} 26 24 03 RCL 3 27 71 ÷ 28 41  E = sum y^{2}  [(sum y)^{2} / n] 29 71 ÷ r^{2} = a_{1} C / E 30 24 04 RCL 4 31 24 07 RCL 7 32 24 01 RCL 1 33 61 × 34 41  35 24 03 RCL 3 36 71 ÷ a_{0} = (sum y  a_{1} sum x) / n /37\ /15 74\ /g NOP\ /Linear or logarithmic curve fit \37/ \15 07/ \g e^{x} / \Exponential or power curve fit 38 23 00 STO 0 39 24 01 RCL 1 40 21 x<>y 41 74 R/S Halt to display a_{0}, a_{1}, r^{2} /42\ /15 74\ /g NOP\ /Linear or exponential curve fit \42/ \14 07/ \f ln / \Logarithmic or power curve fit 43 24 01 RCL 1 44 61 × 45 24 00 RCL 0 /46\ /15 74\ /g NOP\ /Linear or logarithmic curve fit \46/ \14 07/ \f ln / \Exponential or power curve fit 47 51 + /48\ /15 74\ /g NOP\ /Linear or logarithmic curve fit \48/ \15 07/ \g e^{x} / \Exponential or power curve fit 49 13 41 GTO 41
R0 a_{0} R1 a_{1} R2 sum y^{2} R3 n R4 sum y R5 sum xy R6 sum x^{2} R7 sum x
Go back to the software library
Go back to the main exhibit hall