Showing posts with label User Keyboard. Show all posts
Showing posts with label User Keyboard. Show all posts

Saturday, September 30, 2023

HP 15C: Quadratic Regression

HP 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.  Be careful because if a matrix's pointers (row in R0 and column in R1) return to (1,1), while in USER mode, the next program is skipped.  A special acknowledgement to Torsten for pointing this to me.  



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.  #



#  Label A:   Initialization

001 :  42,21,11 :   LBL A

002 :  42,34 :  CLEAR REG

003 :  42,16, 0 :  MATRIX 0

004 :  0 :   0

005 :  43,32  : RTN


# Label B:  Data Entry and Processing

006 : 42,21,12 :  LBL B

007 : 44, 0 :   STO 0

008 :  43,11 : x^2

009 :  34  :  x<>y

010 :  44, 1  : STO 1

011 :  20  :  ×

012 :  44,40,.0 :  STO+ .0  (# store-add to register point zero)

013 :  45, 0  : RCL 0  

014 :  3 :  3

015 :  14 : y^x

016 :  44,40, 8 :  STO+ 8

017 :  45,20, 0 :  RCL× 0

018 :  44,40, 9 : STO+ 9

019 :  45, 1 : RCL 1

020 :  45, 0 : RCL 0

021 :  49  : Σ+

022 :  43,32 : RTN


# Label C:  Calculation

023 : 42,21,13 : LBL C

024 : 3 :  3

025 : 36 : ENTER

026 : 42,23,11 : DIM A

027 : 42,16, 1 : MATRIX A


# Matrix A - Row 1

# Turn on USER Mode ( [ f ] [ RCL ] (USER))

028 : 45, 2 : RCL 2

029 u 44,11 :  STO A

030 : 45, 3 : RCL 3

031 u 44,11 : STO A

032 :  45, 4 :  RCL 4

033 u 44,11 : STO A


# Matrix A - Row 2

034 : 45, 3 : RCL 3

035 u 44,11 : STO A

036 : 45, 4 :  RCL 4

037 u 44,11 : STO A

038 :  45, 8 : RCL 8

039 u 44,11 : STO A


# Matrix A - Row 3

040 : 45, 4 : RCL 4

041 u 44,11 : STO A

042 : 45, 8:  RCL 8

043 u 44,11 : STO A

044 : 45, 9 : RCL 9

045 u 44,11 : STO A

# Turn off USER Mode (unless the next step would be skipped unnecessarily)



# Matrix B

046 : 42,16, 1 : MATRIX 1

047 : 3 :  3

048 : 36 : ENTER

049 : 1 : 1

# Turn on USER Mode

050 : 42,23,12 : DIM B

051 : 45, 5 : RCL 5

052 u 44,12 : STO B

053 : 45, 7 : RCL 7

054 u 44,12 : STO B

055 : 45,.0 : RCL .0   (# recall registers point-zero)

# Turn off USER Mode (unless the next step would be skipped unnecessarily and in this case, an Error 11 would occur)

056 :  44,12 : STO B



# Matrix C - Results

057 : 42,26,13 : RESULT C

058 : 45,16,12 : RCL MATRIX B

059 : 45,16,11 : RCL MATRIX A

060 : 10 : ÷

061 : 42,16, 1 : MATRIX 1

062 u 45,13 : RCL C

063 : 31 : R/S

064 u 45,13 : RCL C

065 : 31 : R/S

066 u 45,13 : RCL C

067 : 43,32 : RTN


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



Enjoy!


Eddie



All original content copyright, © 2011-2023.  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. 


Thursday, September 26, 2013

HP Prime Tip: Setting Up User Keys

HP Prime User Keyboard Primer

On of the features of the new HP Prime is the ability to assign custom programs, mathematical commands, or constants to the keyboard.

In this tutorial, we will use the shortcut commands to set up a user keyboard. You can set one or many user keys, there is no required number. In addition, the user keyboard can take one of four planes:

Key
Shift + Key
ALPHA + Key
Shift + ALPHA + Key

We will illustrate the procedure by assigning the STRING() command to the
Change Sign [ +/- ] key.

1. Create a new program and give it any name you want. For this example, I name the program USERKEY. USERKEY is going to be where I store my user key assignments.

2. Clear the program editor. There should be no EXPORT-BEGIN-END structures on the screen.

3. Press the [Menu] key. The [Menu] key is on the upper right hand corner section of the keys, to the left of the [CAS] key and below the [View] key. Select option 4: "Create User Key".

4. At the "Press any key..." prompt, select the key for which you want to assign your command to.

For my illustration, I will press the [+/-] key.

5. The user key template will appear of the programming editing screen. In between the BEGIN and END; is where you will type.

Note that the appropriate key code will be entered for you.

6. Call the RETURN command by pressing the soft key (Tmplt) then selecting "Block" then "RETURN".

Type your command and program in quotes. You can also call them from the various HP Prime menus or the Catalog. It is very important that you end this line with a semicolon (;), otherwise a syntax error occurs.

Note that user key assignments and edits are saved automatically. There is no need to run the USERKEY program.

Illustrated below is me putting the STRING() command. This assigns the STRING command to the [ +/- ] key.

For additional key assignments, repeat steps 3-6. Each key assignment template stands alone. Do not nest key assignment templates.

To use a user-assigned key, first press [Shift] + [Help] (User). An orange "1U" indicator appears on the top left hand corner of the screen. This means the next key pressed will execute the user-assigned function (if there is one).

For my example, pressing [Shift] + [Help] (User), [+/-] brings up the STRING command.

That is all there is to it!

Be sure to take notes of your key assignments.

Look for additional HP Prime programming tutorials in the upcoming months.

As always thank you for your support and comments. Have a great day everyone,

Eddie


This blog is property of Edward Shore. 2013

RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...