Saturday, December 7, 2024

Casio fx-CG50 and TI-84 Plus CE: Multiple Linear Regression

Casio fx-CG50 and TI-84 Plus CE: Multiple Linear Regression


We have arrived at the last month of 2024. What a crazy year. I hope for smoother and peaceful times ahead.



Introduction


The program MLREG fits bi-variate data to the linear regression equation:


y = b0 + b1 * t + b2 * x


where t and x are the independent variables, and y is the dependent variable. The program uses a numerical method known as normal equations, to solve the system:


n * b0 + Σ(t) * b1 + Σ(x) * b2 = Σ(y)

Σ(t) * b0 + Σ(t^2) * b1 + Σ(t*x) * b2 = Σ(t*y)

Σ(x) * b0 + Σ(t*x) * b1 + Σ(x^2) * b2 = Σ(x*y)


or in matrix form:


[ [ n ,Σ(t), Σ(x) ] [ Σ(t), Σ(t^2), Σ(t*x) ] [ Σ(x), Σ(t*x), Σ(x^2) ] ] * [ [ b0 ] [ b1 ] [ b2 ] ]

= [ [ Σ(y) ] [ Σ(t*y) ] [ Σ(x*y) ] ]


where:

n is the number of data points,

Σ(t) is the sum of all t data,

Σ(x) is the sum of all x data,

Σ(y) is the sum of all y data,

x * t, t * y, x * y, t^2, x^2 are all represent of the variable element-by-element multiplication of each set


The calculator programs assign the following variables:

n * b0 + Σ(t) * b1 + Σ(x) * b2 = Σ(y)

Σ(t) * b0 + Σ(t^2) * b1 + Σ(t*x) * b2 = Σ(t*y)

Σ(x) * b0 + Σ(t*x) * b1 + Σ(x^2) * b2 = Σ(x*y)


A = n

B = Σ(t)

C = Σ(x)

D = Σ(t^2)

E = Σ(t*x)

F = Σ(x^2)

X = Σ(y)

Y = Σ(t*y)

Z = Σ(x*y)




Casio fx-CG 50 Program: MLREG


This is programmed in Casio Basic.


“Y=B0+B1×T+B2×X”

“T LIST”? → List 4

“X LIST”? → List 5

“Z LIST”? → List 6

If Dim List 4 ≠ Dim List 5 Or Dim List 5 ≠ Dim List 6 Or Dim List 4 ≠ Dim List 6

Then

“LISTS NOT SAME LENGTH” ◢

Stop

IfEnd

Dim List 4 → A

Sum List 4 → B

Sum List 5 → C

Sum (List 4²) → D

Sum (List 4 × List 5) → E

Sum (List 5²) → F

Sum List 6 → X

Sum (List 6 × List 4) → Y

Sum (List 6 × List 5) → Z

“B0,B1,B2=” ◢

[ [A, B, C ][B, D, E][C, E, F] ] ⁻¹ × [ [ X ][ Y ][ Z ] ] → Mat Z



TI-84 Plus CE Program: MLREG


ClrHome

Disp “Y=B0+B1*T+B2*X”

Input “T LIST: “, L₄

Input “X LIST: “, L₅

Input “Y LIST: “, L₆

If dim(L₄) ≠ dim(L₅) or dim(L₅) ≠ dim(L₆) or dim(L₄) ≠ dim(L₆)

Then

Disp “LISTS NOT EQUAL SIZE”

Stop

End

dim(L₄) → A

sum(L₄) → B

sum(L₅) → C

sum(L₄ ²) → D

sum(L₄ * L₅) → E

sum(L₅ ²) → F

sum(L₆) → X

sum(L₆ * L₄) → Y

sum(L₆ * L₅) → Z

[ [ A, B, C ] [ B, D, E ] [ C, E, F ] ] ⁻¹ * [ [ X ] [ Y ] [ Z ] ] → [ J ]

Disp “B0,B1,B2= “, [ J ]


Note: [ J ] is matrix J is called form the Matrix menu.



An Online Multiple Linear Regression Calculator


A multiple linear regression calculator which determine coefficients, quadrants, and other statistics can be found on the stats.blue web page: https://stats.blue/Stats_Suite/multiple_linear_regression_calculator.html


Examples


Example 1


t

x

y

1.12

22.3

100

1.16

22.1

104

1.19

21.8

107

1.23

21.4

110

1.28

21.1

114


Result:

B0 = -48.8333333

B1 = 99.99999999 (TI-84 Plus CE rounds this to 100)

B2 = 1.666666666


Equation:

y = -48.8333333 + 99.99999999 * t + 1.666666666 * x



Example 2


t

x

y

10.2

1.95

1000

10.5

3.00

1002

10.8

4.00

1005

11.1

4.95

1007

11.6

5.80

1009

11.8

6.75

1012

12.1

7.80

1015


Result:

B0 = 1008.157502

B1 = -1.429759754

B2 = 3.052897088


y = 1008.157502 – 1.429759754 * t + 3.052897088 * x


Until next time, when a new series will be introduced. Stay tuned,



Eddie


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

Saturday, November 30, 2024

TI-30Xa and HP 12C: Linear Interpolation

TI-30Xa and HP 12C: Linear Interpolation



Introduction


Linear interpolation allows us to estimate a point (x,y) given a linear relationship between points (x1,y1) and (x2,y2).


Given two points (x0, y0) and (x1, y1), and a point, x, we can easily estimate the y coordinate:


y = y0 + (x – x0) * (y1 – y0) / (x1 – x0)


Note that the slope of the line is:

m = (y1 – y0) / (x1 – x0)


This works the best when x is relatively real close to x0 and x1.


Fun fact, the y-intercept, where x = 0 can be calculated as:

b = y0 – x0 * m




TI-30Xa Algorithm: Linear Interpolation


This algorithm will require to enter information only once.


Store the following points:

x0 [ STO ] 1

y0 [ STO ] 2


Predict y:

[ ( ] x [ - ] [ RCL ] 1 [ ) ] [ × ] [ ( ] y1 [ - ] [ RCL ] 2 [ ) ] [ ÷ ] [ ( ] x1 [ - ] [ RCL ] 1 [ ) ] [ + ] y0 [ = ]




HP 12C Algorithm: Linear Interpolation


It turns out that we can use the linear regression functions for linear interpolation. Entering two points for linear regression will create a perfect line (with the correlation of 1 or -1). The algorithm presented is for the HP 12C, and a algorithm for other calculators can easily be made.


Keystrokes:


Enter (x0, y0) and (x1, y1):

[ f ] [ Clx ] (CLEAR FIN)

y0 [ ENTER ] x0 [ Σ+ ]

y1 [ ENTER ] x1 [ Σ+ ]


To calculate y:

x [ g ] [ 2 ] (y-hat, r)



Examples


Examples

X0

Y0

X1

Y1

X (Input)

Y (Output)

1

10

4.95

12

5.06

11

5.0050

2

21

48,057

23

52,165

22

50,111

3

1000

97.7

2000

94.2

1500

95.95



Source


“Linear interpolation” Wikipedia. Was Edited August 27, 2024. Retrieved September 4, 2024. https://en.wikipedia.org/wiki/Linear_interpolation


Until next time, as we head into the final month of 2024,



Eddie


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

Saturday, November 23, 2024

Fun with the HP 30b

Fun with the HP 30b



Introduction





The following programs are for the HP 30b Business Professional. Did you know that the 30b has a programming mode? The program mode has room for 10 programs with a total of 290 steps, where each key press is counted. Thankfully, shifts and hold-shifts are merged steps.


I couldn’t get the MSG or R/S commands to work properly. Therefore I use an approach that I often use for the Voyager calculators (HP 11C, 12C, 15C): store everything first and then run the program.


Disp5 is like the PSE (pause) command, it stops the execution for a second. Disp can be set to 1-9. Disp1 lasts for 1/5 second.


All programs are done in the Algebraic instead of the RPN I usually do on HP calculators.


All the results in the examples, except the last one, are rounded to four decimal places.



Program 0: f(x,y) = (x * y) / (x + y)


f(x, y) = (x * y) / (x + y)


Store x in memory 1 and y in memory 2.


Prog 0 =

RCL 1

×

RCL 2

÷

( ↓

RCL 1

+

RCL 2

) Swap

=

Stop


Examples:

x = 1.5, y = 16; Result: 1.3714

x = 3.6, y = 32; Result: 3.2360

x = 8.7, y = 10; Result: 4.6524



Program 1: PITI – Principal, Interest, Taxes, and Insurance


This program calculates the monthly payment of PI (principal and interest) and PITI (principal, interest, taxes, and insurance). The program assumes that payments per year setting (P/YR) is set to 12.


Store to Memory:

M1: Annual insurance rate.

M2: Annual property tax rate.

N: number of payments

I/YR: interest rate of the loan

PV: amount of the loan


It assumed that there is no balloon payment (FV = 0), although this program can be modified to include balloon payments by removing the first two steps (0 FV).


Prog 1 =

0

FV

PMT

Disp5

Disp5

-

( R↓

RCL 1

+

RCL 2

) Swap

/

1

2

0

0

*

RCL PV

=

Stop


Examples:


N = 360

I/YR = 8.9%

PV = 289000

Insurance Rate = 1% (1 STO 1)

Property Tax Rate = 1.3% (1.3 STO 2)


Result:

PMT: -2304.60

PITI: -2858.51



N = 360

I/YR = 8.9%

PV = 289000

Insurance Rate = 1% (1 STO 1)

Property Tax Rate = 1.3% (1.3 STO 2)


Result:

PMT: -2304.60

PITI: -2858.51



Program 2: Quadratic Equation – Po-Shen Lo Method

This program solves the monic quadratic polynomial:


x^2 + B * x + C = 0


where the solutions:

U^2 = B^2 / 4 – C

x1, x2 = - B / 2 ± √(U^2)


Store to Memory:

M1: B

M2: C


Prog 2 =

RCL 1

X^2

/

4

-

RCL 2

=

STO 0

-

RCL 1

/

2

=

STO 3

Disp5

Disp5

-

2

*

RCL 0

=

STO 4

Stop


M3: root 1 ( -B / 2 + √(U^2) )

M4: root 1 ( -B / 2 + √(U^2) )


This program finds real roots only. If there are no real roots, then the program displays an error.


Examples:


x^2 – 2 * x – 24 = 0

B = -2 STO 1

C = -24 STO 2

Roots: 6, -4


x^2 – 10 * x + 21 = 0

B = -10 STO 1

C = 21 STO 2

Roots: 3, 7



Program 3: Lease with Advanced Payments (HP 12C – see source)


This program calculates the regular monthly payment of a lease when the borrower pays a set number of payments in advance. Payments per year (P/YR) is assumed to be set at 12 while the calculator is set to End of Period payments.


Store in Memory:

number of payments [ N ]

annual lease rate [ I/YR ]

residual value [ FV ]

number of payments to be made in advance [ STO ] 0

loan amount [ STO ] 1 (not PV)


Prog 3 =

0

PMT

0

PV

PV

+

RCL 1

=

STO 2

0

FV

RCL N

-

RCL 0

=

N

1

+/-

PMT

( R↓

PV

+

RCL 0

) Swap

1/X

*

RCL 2

=

Stop


Examples:


Total Payments: 48 [ N ]

Rate: 13 [ I/YR ]

Residual Value: 7,000 [ FV ]

Payments in Advance: 1 [ STO ] 0

Loan Amount: 25,000 [ STO ] 1


Result: -536.06



Total Payments: 60 [ N ]

Rate: 8.8 [ I/YR ]

Residual Value: 12,000 [ FV ]

Payments in Advance: 3 [ STO ] 0

Loan Amount: 118,000 [ STO ] 1


Result: -2,229.71



For those of you in the United States, Happy Thanksgiving!


Source


Hewlett Packard. HP 12C Financial Calculator: User’s Guide. Edition 5. 2008. San Diego, CA. pp. 124-126


Eddie


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

Monday, November 18, 2024

Spotlight: Akron Brass FireCalc Pocket Computer

Spotlight: Akron Brass FireCalc Pocket Computer



Welcome to a special Monday Edition of Eddie’s Math and Calculator blog.



This is an instance of a small gamble and the gamble paid off because the calculator works! I found a one of a kind calculator at the Redlands Thrift Store in Redlands, CA: the Akron Brass FireCalc Pocket Computer. The specialty is mathematical calculations in fire fighting. I paid $4.95, and it probably would cost, I guess $40-$50 or higher retail because this is a specialty calculator.


Akron Brass FireCalc Pocket Computer


Akron Brass FireCalc Pocket Computer


Akron Brass FireCalc Pocket Computer





Quick Facts



Model: FireCalc Pocket Computer

Company: Akron Brass

Timeline: ????

Type: Fire Science Solver, 4 Function Calculator

Memory: No conventional memory registers, but input in the solvers are stored in memory

Power: 2 x LR44 batteries



The four function calculator has a square key, [ x^2 ], along with a square root key [ √ ]. There are two clearing keys:

[ CLEAR DISPLAY ]: acts like as clear entry key, which makes the display show 0.

[ ALL CLEAR ]: clears all the registers, and the display shows AKRON.



The display holds room for 8 digits. The display also shows alphabetic characters being built from segments.

Disclaimer: I am not a fire fighter or an expert in fire fighting mathematics. This is another topic to explore. I am going to do the best I can in describing the functions of the calculator.



A Solver for Fire Fighters



The FireCalc Pocket Computer features eight solvers. I’m going to be give a summary of how each solver as described as in the manual (see the manual section below). The solvers are the top two rows of blue keys. U.S. units are used.


There are four rows of gray keys with measurements marked ¾” all the way to 6”. Those are quick entry keys. For example, pressing [ 1 ¾” ] enters 1.75 in one keystroke.



The solvers are:



[ ENGINE PRESSURE ]: calculates the engine pressure in psi (pounds per square inch) of the water hose (I think) given the pressure, flow (gallons per minute), and length of the hose. There is also a prompt for the number of Siamese lines used (defaults to 1).

[ FRICTION LOSS ]: calculates the friction loss of a hose lay given the hose size and length. The loss is shown in psi.

(FLOW RATE) [ STRAIGHT TIP ] or [ FOG NOZZLE ]: Find the flow rate of water through the hose when it is a straight bore tip or fog nozzle in GPM (gallons per minute), respectively. For the fog nozzle, the rated nozzle pressure is skipped (the manual has it prompted).

(REACTION FORCE) [ STRAIGHT TIP ] or [ FOG NOZZLE ]: Find the reaction force in Lbs (pounds fource) of water through the hose when it is a straight bore tip or fog nozzle, respectively.

[ APPLIC. RATE ]: Find the minimum rate of water, in GPM, that is required to extinguish a fire given the rooms’ length, width, and height in feet.

[ RATE OF FLOW ]: I did not see this calculation the manual, but given from the prompts, this calculates the rate of flow of water given the following parameters: nozzle pressure, English pressure, hose size, number of Siamese lines used, number of floors, and hose length.









Because the number of solvers don’t match the manual exactly, I think this model either predates or succeeds the model described in the manual. On the back of the project it states “Cygnus of South Florida Electric Calculator. Project No. 302”. Does that mean anything?



Manual


Manual to the FireCalc from Akron Brass Company, written in 2008. It’s not the exact module that I have, but it’s pretty close: https://smhttp-ssl-61500.nexcesscdn.net/media/pdf/9900_FireCalcInstructions.pdf



Until next time, be safe and wishing you happiness (and safety from fires),



Eddie


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

Casio fx-CG50 and TI-84 Plus CE: Multiple Linear Regression

Casio fx-CG50 and TI-84 Plus CE: Multiple Linear Regression We have arrived at the last month of 2024. What a crazy year. I hope for...