(15C) Quadratic Regression
|
07-24-2023, 03:47 AM
(This post was last modified: 07-29-2023 05:49 PM by Eddie W. Shore.)
Post: #1
|
|||
|
|||
(15C) Quadratic Regression
Setup, Normal Equations, and Registers Used
This program fits bivariate date (x,y) to the quadratic polynomial: y = c + b * x + a * x^2 This program uses the matrix feature of the HP 15C. The normal equations that are solved are: n * c + Σx * b + Σx^2 * a = Σy Σx *c + Σx^2 * b + Σx^3 *a = Σxy Σx^2 * c + Σx^3 * b + Σx^4 * a = Σ(x^2 y) Matrix A = [ [ n, Σx, Σx^2 ] [ Σx, Σx^2, Σx^3 ] [ Σx^2, Σx^3, Σx^4 ] ] Matrix B = [ [ Σy ] [ Σxy ] [ Σ(x^2 y) ] ] Matrix C = (Matrix B)^-1 Matrix A [ [ c ] [ b ] [ a ] ] Registers Used: R0: x data point, row pointer R1: y data point, column pointer Default Statistics Registers: R2: n R3: Σx R4: Σx^2 R5: Σy R6: Σy^2 R7: Σxy Additional Statistics Registers: R8: Σx^3 R9: Σx^4 R.0: Σ(x^2 y) ("register point zero": press the decimal point before the 0) Instructions 1. 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. 2. 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. 3. 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. HP 15C Program Code: Quadratic Regression Program Memory: 67 steps, 90 bytes Needs 15 additional memory registers to store the three matrices. Comments begin with a hash symbol. # Code: # Label A: Initialization (Typos pointed to me by Torsten. The key codes are now correct.) Examples Example 1: (3, 1.3) (4, 1.6) (5, 1.5) (6, 1.4) c = -0.54 b = 0.92 a = -0.1 y = -0.54 + 0.92 x - 0.1 x^2 Example 2: (0, 99.856) (3, 97.232) (5, 93.481) (7, 96.005) (10, 102.008) c ≈ 100.3437 b ≈ -2.5318 a ≈ 0.2495 y ≈ 100.3437 - 2.5318 x + 0.2495 x^2 |
|||
07-25-2023, 11:04 PM
Post: #2
|
|||
|
|||
RE: (15C) Quadratic Regression
Cool use of matrices for quadratic regression!!
Namir |
|||
07-26-2023, 04:59 AM
Post: #3
|
|||
|
|||
RE: (15C) Quadratic Regression
Thank you, Namir!
Eddie |
|||
07-29-2023, 05:47 PM
Post: #4
|
|||
|
|||
RE: (15C) Quadratic Regression
One thing I noticed after running the program is that when I recalled Matrix A, the display shows a couple of dashes after A: A - - 3 3. I was not able to find anything in the manual, do you know if the dashes are significant?
|
|||
07-29-2023, 06:18 PM
Post: #5
|
|||
|
|||
RE: (15C) Quadratic Regression
From the Advanced Function Handbook (pp. 96):
Understanding the LU Decomposition Quote:The decomposition is flagged in the process, and its descriptor includes two dashes when displayed. |
|||
08-01-2023, 10:04 AM
Post: #6
|
|||
|
|||
RE: (15C) Quadratic Regression
Here is another program that solves the following equation for \(\mathbf{c}\):
\( \mathbf{A}^\top \mathbf{A} \mathbf{c} = \mathbf{A}^\top \mathbf{b} \) It stores the data in the matrices \(\mathbf{A}\) and \(\mathbf{b}\). This can be useful if you only want to change the y-values so you don't have to re-enter the x-values. However, the disadvantage is that due to the limited memory, a maximum of 11 data points can be entered. Code: 001 { 42 21 11 } f LBL A Important: Make sure to have USER mode active while entering the program. Example (0, 99.856) (3, 97.232) (5, 93.481) (7, 96.005) (10, 102.008) Initialisation: USER 0 DIM (i) MATRIX 0 5 ENTER 3 DIM A 5 ENTER 1 DIM B Enter the x-values: A 1.0000 0 R/S 2.0000 3 R/S 3.0000 5 R/S 4.0000 7 R/S 5.0000 10 R/S Enter the y-values: B 1.0000 99.856 R/S 2.0000 97.232 R/S 3.0000 93.481 R/S 4.0000 96.005 R/S 5.0000 102.008 R/S Calculate the coefficients: C running RCL C 100.3437 RCL C -2.5318 RCL C 0.2495 |
|||
08-03-2023, 01:53 PM
Post: #7
|
|||
|
|||
RE: (15C) Quadratic Regression
Revised code: with comments on user mode.
Code: # Label A: Initialization |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)