RPN with HP 15C & DM32: Expanding Linear Regression
“Linearize” the Equation
The linear regression mode of the HP 15C and Swiss Micros DM32 can be expanded to fit different curves for bi-variate data.
Curves can be set up for linear regression if we can get the equation into the form:
y = b + m * x ⇒ f(y) = b + m * g(x)
where b is the y-intercept and x is the slope. The correlation is r and r^2 can be used to determine the relationship between x (independent) and y (dependent) variables. If r^2 is close to 1, the better the curve fits to the data.
Note: f(y) and g(x) are functions that contain only one term (sin y, cos y, e^y, 1/y, y^2 …. sin x, cos x, e^x, 1/x, x^2, ….)
The DM32 labels the slope as m, y-intercept as b. Each of the parameters can be recalled separately.
The HP 12C labels the slope as a, y-intercept as b. Both a and b are calculated by the key sequence [ f ] [ Σ+ ] (L.R.): slope is on the y-stack and the y-intercept is on the x-stack. To get the correlation, enter any (valid) number and press [ f ] [ . ] (y-hat, r) [ x<>y ].
Let’s illustrate this for with a couple of examples.
y = 1 / (b + m * e^(-x))
1/y = b + m * e^(-x)
We have the equation in the required form with the following adjustments: x’ = e^(-x), y’ = 1/x.
y = b * m^x
ln y = ln (b * m^x)
ln y = ln b + ln (m^x)
ln y = ln b + x * ln m
We have the equation in the required form with the following adjustments: x’ = x, y’ = ln y.
Now note that we have ln b and ln m. This will require an adjustment when the linear regression is calculated. To get the “true” slope and y-intercept in this case, we must calculate e^b and e^m.
To employ different curve fittings, I use (at least) two programs:
Entering data (DM32, HP15C):
LBL #
g(x)
x<>y
f(y)
x<>y
Σ+
R/S
GTO #
Entering data:
CLEAR Σ (CLΣ)
y1 ENTER x1 XEQ/GSB #
yn ENTER xn R/S
You can enter as many data points as you like.
Calculating the Parameters:
DM32:
LBL @
b
(adjustments if needed)
R/S
m
(adjustments if needed)
R/S
r
x^2
RTN
HP 15C:
LBL @
L.R.
(adjustment if needed)
R/S
x<>y
(adjustment if needed)
R/S
1
y-hat, r
x<>y
x^2
RTN
Example 1: y = 1 / (b + m * e^(-x))
Linearized: 1 / y = b + m * e^(-x)
Adjustments: x’ = e^(-x), y’ = 1 / y, no adjustment to b or m
Enter Data:
HP 15C Code |
HP 15C Key |
DM32 |
42, 21, 11 |
LBL A |
LBL D |
16 |
CHS |
+/- |
12 |
e^x |
e^x |
34 |
x<>y |
x<>y |
15 |
1/x |
1/x |
34 |
x<>y |
x<>y |
49 |
Σ+ |
Σ+ |
31 |
R/S |
R/S |
22, 11 |
GTO A |
GTO D |
Calculating the Parameters:
HP 15C Code |
HP 15C Key |
DM32 |
42, 21, 1 |
LBL 1 |
LBL R |
42, 49 |
L.R. |
b |
31 |
R/S |
R/S |
34 |
x<>y |
m |
31 |
R/S |
R/S |
1 |
1 |
r |
42, 48 |
y-hat, r |
x^2 |
34 |
x<>y |
RTN |
43, 11 |
x^2 |
|
43, 32 |
RTN |
|
Example:
x |
y |
0.0 |
0.125 |
0.1 |
0.13 |
0.2 |
0.134 |
0.3 |
0.138 |
0.4 |
0.143 |
0.5 |
0.147 |
Results (FIX 5):
|
HP 15C |
DM32 |
Intercept (b) |
4.98312 |
4.98312 |
Slope (m/a) |
3.01575 |
3.01575 |
r^2 |
0.99841 |
0.99841 |
Example 2: y = ln(b + m * e^(-x))
Linearized: e^y = b + m * e^(-x)
Adjustments: x’ = e^(-x), y’ = e^(y), no adjustment to b or m
Enter Data:
HP 15C Code |
HP 15C Key |
DM32 |
42, 21, 12 |
LBL B |
LBL E |
16 |
CHS |
+/- |
12 |
e^x |
e^x |
34 |
x<>y |
x<>y |
12 |
e^x |
e^x |
34 |
x<>y |
x<>y |
49 |
Σ+ |
Σ+ |
31 |
R/S |
R/S |
22, 12 |
GTO B |
GTO E |
Calculating the Parameters:
HP 15C Code |
HP 15C Key |
DM32 |
42, 21, 1 |
LBL 1 |
LBL R |
42, 49 |
L.R. |
b |
31 |
R/S |
R/S |
34 |
x<>y |
m |
31 |
R/S |
R/S |
1 |
1 |
r |
42, 48 |
y-hat, r |
x^2 |
34 |
x<>y |
RTN |
43, 11 |
x^2 |
|
43, 32 |
RTN |
|
Example:
x |
y |
0.98 |
1.946 |
0.99 |
1.942 |
1.00 |
1.938 |
1.01 |
1.934 |
1.02 |
1.929 |
1.03 |
1.925 |
Results (FIX 5):
|
HP 15C |
DM32 |
Intercept (b) |
3.99987 |
3.99985 |
Slope (m/a) |
8.00051 |
8.00056 |
r^2 |
0.99844 |
0.99844 |
*differences may be due to rounding error in the internal algorithms
Example 3: y = √(b + m * x^2)
Linearized: y^2 = b + m * x^2
Adjustments: x’ = x^2, y’ = y^2, no adjustment to b or m
Enter Data:
HP 15C Code |
HP 15C Key |
DM32 |
42, 21, 13 |
LBL C |
LBL F |
43, 11 |
x^2 |
x^2 |
34 |
x<>y |
x<>y |
43, 11 |
x^2 |
x^2 |
34 |
x<>y |
x<>y |
49 |
Σ+ |
Σ+ |
31 |
R/S |
R/S |
22, 13 |
GTO C |
GTO F |
Calculating the Parameters:
HP 15C Code |
HP 15C Key |
DM32 |
42, 21, 1 |
LBL 1 |
LBL R |
42, 49 |
L.R. |
b |
31 |
R/S |
R/S |
34 |
x<>y |
m |
31 |
R/S |
R/S |
1 |
1 |
r |
42, 48 |
y-hat, r |
x^2 |
34 |
x<>y |
RTN |
43, 11 |
x^2 |
|
43, 32 |
RTN |
|
Example:
x |
y |
1.05 |
2.066 |
1.25 |
2.337 |
1.45 |
2.620 |
1.65 |
2.912 |
1.85 |
3.209 |
2.05 |
3.511 |
Results (FIX 5):
|
HP 15C |
DM32 |
Intercept (b) |
1.40009 |
1.40009 |
Slope (m/a) |
2.59996 |
2.59996 |
r^2 |
1.00000 |
1.00000 |
Example 4: y = b * m^x
Linearized: ln y = ln b + x * ln m
Adjustments: x’ = x, y’ = ln y, result adjustments: e^b, e^m
Enter Data:
HP 15C Code |
HP 15C Key |
DM32 |
42, 21, 14 |
LBL D |
LBL G |
34 |
x<>y |
x<>y |
43, 12 |
LN |
LN |
34 |
x<>y |
x<>y |
49 |
Σ+ |
Σ+ |
31 |
R/S |
R/S |
22, 14 |
GTO D |
GTO G |
Calculating the Parameters:
HP 15C Code |
HP 15C Key |
DM32 |
42, 21, 2 |
LBL 2 |
LBL S |
42, 49 |
L.R. |
b |
12 |
e^x |
e^x |
31 |
R/S |
R/S |
34 |
x<>y |
m |
12 |
e^x |
e^x |
31 |
R/S |
R/S |
1 |
1 |
r |
42, 48 |
y-bar, r |
x^2 |
34 |
x<>y |
RTN |
43, 11 |
x^2 |
|
43, 32 |
RTN |
|
Example:
x |
y |
0.84 |
2.358 |
0.87 |
2.363 |
0.90 |
2.369 |
0.93 |
2.374 |
0.96 |
2.379 |
0.99 |
2.385 |
Results (FIX 5):
|
HP 15C |
DM32 |
Intercept (b) |
2.21302 |
2.21302 |
Slope (m/a) |
1.07843 |
1.07843 |
r^2 |
0.99916 |
0.99919 |
*differences may be due to rounding error in the internal algorithms
Expanding Linear Regression Table
Regression |
X |
Y |
B = ITC |
M = SLP |
Logarithmic: y = b + m * ln x |
ln x |
y |
b |
m |
Exponential: y = b * e^(m*x) |
x |
ln y |
e^b |
m |
Inverse: y = b + m/x |
1/x |
y |
b |
m |
Power: y = b * x^m |
ln x |
ln y |
e^b |
m |
General Exponential: y = b * m^x |
x |
ln y |
e^b |
e^m |
Simple Logistic: y = 1/(b + m * e^(-x)) |
e^(-x) |
1/y |
b |
m |
Square Root Linear: y = √(b + m * x) |
x |
y^2 |
b |
m |
Cosine: y = b + m*cos(ω(x – ϕ)) With ϕ = the point (x) nearest to zero where the trough or peak begins ω = (2*π)/period (radians) or ω = 360°/period (degrees) |
cos(ω(x – ϕ)) |
y |
b |
m |
Logarithmic-Linear-Exponential: y = ln(b + m * e^(-x)) |
e^(-x) |
e^y |
b |
m |
Square Root Quadratic: y = √(b + m * x^2) |
x^2 |
y^2 |
b |
m |
Eddie
All original content copyright, © 2011-2025. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.