Quadratic Regression
Description
By Eddie Shore, July 2023 in the MoHPC - General Software Library
This program fits bivariate date (x,y) to the quadratic polynomial:
y = c + b·x + a·x2
This program uses the matrix feature of the HP 15C. The normal equations that are solved are:
n·c + Σx·b + Σx2·a = Σy
Σx·c + Σx2·b + Σx3·a = Σxy
Σx2·c + Σx3·b + Σx4·a = Σ(x2y)
Matrix A
[ [ n, Σx, Σx2 ]
[ Σx, Σx2, Σx3 ]
[ Σx2, Σx3, Σx4 ] ]
Matrix B:
[ [ Σy ]
[ Σxy ]
[ Σ(x2y) ] ]
Matrix C = (Matrix B)-1 · Matrix A:
[ [ c ]
[ b ]
[ a ] ]
Instructions:
- Run label A to clear the matrices and registers. This needs to be done in order to get the most accurate results. Zero is displayed to indicate when the calculator is ready.
- For each point, enter y data point, press ENTER, x data point, and run label B. The number of data points (n) will be displayed.
- To calculate the coefficients, run label C. The coefficients c, b, and a are displayed in order.
Matrix Operations Used:
MATRIX 0: clear all the matrices
MATRIX 1: sets the row and counter pointer to 1,1.
User Mode Set: automatically advances the pointer to the right row by row. In programs, turning on and off User Mode is not a step. However, storage and recall operations in User Mode are marked with a "u" after the step number.
Example 1:
1.3 ENTER 3 B
1.6 ENTER 4 B
1.5 ENTER 5 B
1.4 ENTER 6 B
f C
c = -0.54 R/S
b = 0.92 R/S
a = -0.1
y = -0.54 + 0.92 x - 0.1 x2
Example 2:
99.856 ENTER 0 B
97.232 ENTER 3 B
93.481 ENTER 5 B
96.005 ENTER 7 B
102.008 ENTER 10 B
c ≈ 100.3437 R/S
b ≈ -2.5318 R/S
a ≈ 0.2495
y ≈ 100.3437 - 2.5318 x + 0.2495 x2
Program Resources
Labels
Storage Registers
Name |
Description |
|
Name |
Description |
|
0 |
x data point, row pointer |
|
6 |
|
|
1 |
y data point, column pointer |
|
7 |
Σxy |
|
2 |
n |
|
8 |
Σx³ |
|
3 |
Σx |
|
9 |
Σx⁴ |
|
4 |
Σx² |
|
.0 |
Σ(x²y) |
|
5 |
Σy |
|
|
|
|
Program
Line |
Display |
Key Sequence |
|
Line |
Display |
Key Sequence |
|
Line |
Display |
Key Sequence |
|
000 |
|
|
|
023 |
42,21,13 |
f LBL C |
|
046 |
42,16, 1 |
f MATRIX 1 |
|
001 |
42,21,11 |
f LBL A |
|
024 |
3 |
3 |
|
047 |
3 |
3 |
|
002 |
42 34 |
f REG |
|
025 |
36 |
ENTER |
|
048 |
36 |
ENTER |
|
003 |
42,16, 0 |
f MATRIX 0 |
|
026 |
42,23,11 |
f DIM A |
|
049 |
1 |
1 |
|
004 |
0 |
0 |
|
027 |
42,16, 1 |
f MATRIX 1 |
|
050 |
42,23,12 |
f DIM B |
|
005 |
43 32 |
g RTN |
|
028 |
45 2 |
RCL 2 |
|
051 |
45 5 |
RCL 5 |
|
006 |
42,21,12 |
f LBL B |
|
029 |
u 44 11 |
USER STO A |
|
052 |
u 44 12 |
USER STO B |
|
007 |
44 0 |
STO 0 |
|
030 |
45 3 |
RCL 3 |
|
053 |
45 7 |
RCL 7 |
|
008 |
43 11 |
g x² |
|
031 |
u 44 11 |
USER STO A |
|
054 |
u 44 12 |
USER STO B |
|
009 |
34 |
x↔y |
|
032 |
45 4 |
RCL 4 |
|
055 |
45 .0 |
RCL . 0 |
|
010 |
44 1 |
STO 1 |
|
033 |
u 44 11 |
USER STO A |
|
056 |
44 12 |
STO B |
|
011 |
20 |
× |
|
034 |
45 3 |
RCL 3 |
|
057 |
42,26,13 |
f RESULT C |
|
012 |
44,40, .0 |
STO + . 0 |
|
035 |
u 44 11 |
USER STO A |
|
058 |
45,16,12 |
RCL MATRIX B |
|
013 |
45 0 |
RCL 0 |
|
036 |
45 4 |
RCL 4 |
|
059 |
45,16,11 |
RCL MATRIX A |
|
014 |
3 |
3 |
|
037 |
u 44 11 |
USER STO A |
|
060 |
10 |
÷ |
|
015 |
14 |
yˣ |
|
038 |
45 8 |
RCL 8 |
|
061 |
42,16, 1 |
f MATRIX 1 |
|
016 |
44,40, 8 |
STO + 8 |
|
039 |
u 44 11 |
USER STO A |
|
062 |
u 45 13 |
USER RCL C |
|
017 |
45,20, 0 |
RCL × 0 |
|
040 |
45 4 |
RCL 4 |
|
063 |
31 |
R/S |
|
018 |
44,40, 9 |
STO + 9 |
|
041 |
u 44 11 |
USER STO A |
|
064 |
u 45 13 |
USER RCL C |
|
019 |
45 1 |
RCL 1 |
|
042 |
45 8 |
RCL 8 |
|
065 |
31 |
R/S |
|
020 |
45 0 |
RCL 0 |
|
043 |
u 44 11 |
USER STO A |
|
066 |
u 45 13 |
USER RCL C |
|
021 |
49 |
∑+ |
|
044 |
45 9 |
RCL 9 |
|
067 |
43 32 |
g RTN |
|
022 |
43 32 |
g RTN |
|
045 |
44 11 |
STO A |
|
|
|
|
|