[go: up one dir, main page]

Showing posts with label HP 12c. Show all posts
Showing posts with label HP 12c. Show all posts

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, July 6, 2024

HP 12C: Hyperbolic Sine and Cosine, and their Inverses

HP 12C: Hyperbolic Sine and Cosine, and their Inverses


Introduction


The following program calculates four hyperbolic functions:


sinh x = (e^x – e^(-x)) / 2

cosh x = (e^x + e^(-x)) / 2

arcsinh x = ln(x + √(x^2 + 1))

arccosh x = ln(x + √(x^2 - 1)) (principal arccosh x)



HP 12C Program: sinh x, cosh x, arcsinh x, arccosh x



Step #: Step Code: [ keys ]


# sinh x: GTO 01, R/S

01: __, 43, 22: [ g ] e^x

02: __, 43, 36: [ g ] LST x

03: __, __, 16: [ CHS ]

04: __, 43, 22: [ g ] e^x

05: __, __, 30: [ - ]

06: __, __, _2: [ 2 ]

07: __, __, 10: [ ÷ ]

08: 43, 33, 00: [ g ] GTO 00


# cosh x: GTO 09, R/S

09: __, 43, 22: [ g ] e^x

10: __, 43, 36: [ g ] LST x

11: __, __, 16: [ CHS ]

12: __, 43, 22: [ g ] e^x

13: __, __, 40: [ + ]

14: __, __, _2: [ 2 ]

15: __, __, 10: [ ÷ ]

16: 43, 33, 00: [ g ] GTO 00


# arcsinh x: GTO 17, R/S

17: __, __, 36: [ ENTER ]

18: __, __, 36: [ ENTER ]

19: __, __, _2: [ 2 ]

20: __, __, 21: [ y^x ]

21: __, __, _1: [ 1 ]

22: __, __, 40: [ + ]

23: __, 43, 21: [ √ ]

24: __, __, 40: [ + ]

25: __, 43, 23: [ g ] LN

26: 43, 33, 00: [ g ] GTO 00


# arccosh x: GTO 27 R/S

27: __, __, 36: [ ENTER ]

28: __, __, 36: [ ENTER ]

29: __, __, _2: [ 2 ]

30: __, __, 21: [ y^x ]

31: __, __, _1: [ 1 ]

32: __, __, 30: [ - ]

33: __, 43, 21: [ √ ]

34: __, __, 40: [ + ]

35: __, 43, 23: [ g ] LN

36: 43, 33, 00: [ g ] GTO 00



Instructions


1. Enter x

2. To calculate, press [ g ] GTO ##, then press [ R/S ].

* GTO 01 R/S: sinh x

* GTO 09 R/S: cosh x

* GTO 17 R/S: arcsinh x

* GTO 27 R/S: arccosh x


Examples

(Fix 4)

x

sinh x

cosh x

-0.64

-0.6846

1.2119

0.59

0.6248

1.1792

1.23

1.5645

1.8568

3.74

21.0371

21.0609


Note: arccosh(1.2119) returns 0.64



Source


Selby, Samuel M. Ph. D. Sc. D. CRC Standard Mathematics Tables: Nineteenth Edition. The Chemical Rubber Co. Cleveland, OH. 1971. pp. 202, 211



Until next time,

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.

Sunday, February 4, 2024

Some RPN Routines: Including Maximum and Minimum of Two Numbers

Some RPN Routines:  Including Maximum and Minimum of Two Numbers



Here are some RPN routines that hopefully you find helpful.   I am assuming that the values are stored in memory registers before calculation and a general four-level stack is used (HP 11C, 12C, 15C, 42S, 32S, 32SII, DM41X, DM32, DM42, DM15, WP34, etc.).  



(a + b + c) × (a + b - c)


Assume that: 

Memory register 1 = a

Memory register 2 = b

Memory register 3 = c

(Your memory registers may have different names or labels)



If recall arithmetic is allowed:


RCL 3

RCL 1

RCL+ 2

+

LST x

RCL- 3

×


(LST x = LAST x)


If recall arithmetic isn't available:


RCL 3

RCL 1

RCL 2

+

+

LST x

RCL 3

-

×



Example:  a= 10, b = 2, c = 7.   Result:  95



 (s + a) × (s + b) × (s + c)


Assume that: 

Memory register 1 = a

Memory register 2 = b

Memory register 3 = c

Memory register 4 = s

(Your memory registers may have different names or labels)


If recall arithmetic is allowed:


RCL 4

ENTER

ENTER

ENTER

RCL+ 1

x<>y

RCL+ 2

×

x<>y

RCL+ 3

×


If recall arithmetic isn't available:


RCL 4

ENTER

ENTER

ENTER

RCL 1

+

x<>y

RCL 2

+

×

x<>y

RCL 3

+

×


Example:  a = 4, b = 8, c = 2, s = 3.   Result:  385



 (s - a) × (s - b) × (s - c)


Assume that: 

Memory register 1 = a

Memory register 2 = b

Memory register 3 = c

Memory register 4 = s

(Your memory registers may have different names or labels)


If recall arithmetic is allowed:


RCL 4

ENTER

ENTER

ENTER

RCL- 1

x<>y

RCL- 2

×

x<>y

RCL- 3

×


If recall arithmetic isn't available:


RCL 4

ENTER

ENTER

ENTER

RCL 1

-

x<>y

RCL 2

-

×

x<>y

RCL 3

-

×


Example:  a = 8, b = 10, c = 3, s = 24.   Result:  4,704



The Maximum and Minimum of the X and Y Stacks



In a program, we can arrange the stack to show the maximum and minimum between two numbers as follows:



Maximum on the X Stack, Minimum on the Y Stack:


...

x≤y   

x<>y

...


If the value of x is less than or equal to y, swap the stack values.  Otherwise, leave the stack as is.



Minimum on the X Stack, Maximum on the X Stack:


HP 12C, HP 11C, HP 10C, and the HP 41C/DM41 family, due to the lack of the  x≥y command:


... 

x≤y

x<>y

x<>y

...


Same routine as the maximum routine, except an extra swap command is placed.



All others:


... 

x≥y

x<>y

...


x≥y is TEST 9 on the HP 15C.  


If the value of x is greater than or equal to y, swap the stack values.  Otherwise, leave the stack as is.

Of course, if your calculator has the maximum (MAX) and minimum (MIN) functions, by all means, use them.  



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, December 16, 2023

HP 12C: Simple Interest

HP 12C:   Simple Interest


Some short-term loans and accounts accrue interest using the simple interest method.   This is different from the conventional compound interest method.  


Simple Interest Formula


T = B + B × R% × N = P × (1 + R% × N)


T = total future value (uses the FV register)

B = beginning value (uses the PV register)

R = annual interest rate (uses the i register)

N = time in years (uses the n register)


The program uses four of the TVM registers for the purpose of storing registers in a convenient way.  



HP 12C Code:  Simple Interest


Step :  Key Code  :  Key


# Solve for the future value, GTO 01, R/S


01:  __, 45, 13:  RCL PV

02:  __, 45, 12:  RCL i

03:  __, 45, 11:  RCL n

04:  __, __, 20:  ×

05:  __, __, 25:  %

06:  __, __, 40:  +

07:  __, 44, 15:  STO FV

08:  43, 33, 00:  GTO 00


# Solve for the present value, GTO 09, R/S 


09:  __, 45, 15:  RCL FV

10:  __, __, _1:  1

11:  __, 45, 12:  RCL i

12:  __, 45, 11:  RCL n

13:  __, __, 20:  ×

14:  __, __, 25:  %

15:  __, __, 40:  +

16:  __, __, 10:  ÷

17:  __, 44, 13:  STO PV

18:  43, 33, 00:  GTO 00


#  Solve for the time in years, GTO 19, R/S


19:  __, 45, 15:  RCL FV

20:  __, 45, 13:  RCL PV

21:  __, __, 10:  ÷

22:  __, __, _1:  1

23:  __, __, 30:  -

24:  __, 45, 12:  RCL i

25:  __, __, 10:  ÷

26:  __, __, _1:  1

27:  __, __, 26:  EEX

28:  __, __, _2:  2

29:  __, __, 20:  ×

30:  __, 44, 11:  STO n

31:  43, 33, 00:  GTO 00


# Solve for the interest rate, GTO 32, R/S 


32:  __, 45, 15:  RCL FV

33:  __, 45, 13:  RCL PV

34:  __, __, 10:  ÷

35:  __, __, _1:  1

36:  __, __, 30:  -

37:  __, 45, 11:  RCL n

38:  __, __, 10:  ÷

39:  __, __, _1:  1

40:  __, __, 26:  EEX

41:  __, __, _2:  2

42:  __, __, 20:  ×

43:  __, 44, 12:  STO i

44:  43, 33, 00:  GTO 00



Summary


T = B + B × R% × N


To solve for T:  GTO 01, [ R/S ]

To solve for B: GTO 09, [ R/S ]

To solve for N:  GTO 19, [ R/S ]

To solve for R:  GTO 32, [ R/S ]



Examples


1.   What is the interest rate required if you begin with $1,000.00 and end up with $1,135.00 in 5 years?  Assume that account accrues using simple interest.


1000 [ PV ] 

1135 [ FV ]

5 [ n ]

GTO 32, [ R/S ]


Answer:  2.70%.  


2.  An auto loan of $8,000.00 is to paid back in 60 monthly payments (5 years).  The loan's rate is 6% at simple interest.   What is the monthly payment of this loan?


The first step is to find the total amount:


8000 [ PV ]

6 [ i ] 

5 [ n ]

GTO 01, [ R/S ]


T = $10,400.00  (total plus interest)


[ RCL ] [ FV ] 60 [ ÷ ]


Monthly payment with simple interest:  $ 173.33



Source


Hayes, Adam.  "Simple Interest: Who Benefits, With Formula and Example"  Investopedia.  Last updated May 27, 2023.  Retrieved November 19, 2023.  

URL:  https://www.investopedia.com/terms/s/simple_interest.asp




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. 


Saturday, August 5, 2023

HP 12C: Log-Normal Distribution Parameter Conversions

HP 12C:   Log-Normal Distribution Parameter Conversions


Introduction

The log-normal distribution is transformation of a standard normal variable, where for a standard normal variable t, then a random variable x follows a log-normal distribution, with the form:

x = e^(μ + t * σ)

where:

μ = mean
σ = standard deviation (sample)

The distribution takes the positive values of x.  The cumulative distributive function of the log-normal distribution (the area between 0 and x) is:

pdf = 1/2 * (1 + erf((ln x - μ) ÷ (σ * √2)) )

erf is the error function.

erf(θ) = 2 ÷ √(π) * ∫(e^(-s^2) ds, s = 0 to s = θ)


This program on today's blog focuses on the relationship between the distribution mean (μ), standard deviation (σ), the arithmetic expected value (E[x]), and the arithmetic variance (Var[x]):

E[x] =e^(μ + σ^2 ÷ 2)

Var[x] = (e^(σ^2) - 1) * e^(2 * μ + σ^2)

μ = ln( E[x]^2 ÷ √(Var[x] + E[x]^2) )

σ = √( ln (1 + Var[x] ÷ E[x]^2 ) )


HP 12C Program:  Log-Normal Distribution Parameter Conversions


Calculate E[x] and Var[x] from μ and σ

Instructions:

To find E[x] and Var[x]:
1.  Store μ in memory register 1
2.  Store σ in memory register 2
3.  Run the program.  E[x] is shown in the X stack and is stored in memory register 3.  Var[x] is shown in the Y stack in memory register 4.  

Code:
(Step:  Key Code:   Key)
(assume program starts with step 00)

01:  45, 2:   RCL  2
02:  2:    2
03:  21:  y^x
04:  44, 0:   STO 0
05:  43, 22:  e^x
06:  1:  1
07:  30:  -
08:  2:  2
09:  45, 1:  RCL 1
10:  20:  ×
11:  45, 0:  RCL 0
12:  40:  +
13:  43, 22:  e^x
14:  20:  ×
15:  44, 4:  STO 4
16:  45, 0:  RCL 0
17:  2:   2
18:  10:  ÷
19:  45, 1:  RCL 1
20:  40:   +
21:  43, 22:  e^x
22:  44, 3:  STO 3
23:  44, 33, 00:  GTO 00

Lines 01 to 03:   Store σ^2 in memory register 0


Examples  (answers are rounded to four decimal places):

Example 1
Inputs:  μ = 1, σ = 0.5
Results:  E[x] = 3.0802, Var[x] = 2.6948

Example 2
Inputs:  μ = 0, σ = 1
Results:  E[x] = 1.6487,  Var[x] = 4.6708


Calculate μ and σ from E[x] and Var[x]


Instructions

To find μ and σ:
1.  Store E[x] in memory register 3
2.  Store Var[x] in memory register 4
3.  Run the program.  μ is shown in the X stack and is stored in memory register 1.  σ is shown in the Y stack in memory register 2.  

Code:
(Step:  Key Code:   Key)
(assume program starts with step 00)

01:  45, 4:  RCL 4
02:  45, 3:  RCL 3
03:  2:   2
04:  21:  y^x
05:  44, 0:  STO 0
06:  10:  ÷
07:  1:  1
08:  40:  +
09:  43, 23:  LN
10:  43, 21:  √
11:  44, 2:  STO 2
12:  45, 0:  RCL 0
13:  45, 0:  RCL 0
14:  45, 4:  RCL 4
15:  40:  +
16:  43, 21:  √
17:  10:  ÷
18:  43, 23:  LN
19:  44, 1:  STO 1
20:  43, 33, 00:  GTO 00

Lines 01 to 03:   Store E[x]^2 in memory register 0
Lines 12 to 13:   Put two copies of memory register 0 on to the stack

Examples  (answers are rounded to four decimal places):

Example 1
Inputs:  E[x] = 1.84, Var[x] = 0.36
Results:  μ = 0.5592,  σ = 0.3180

Example 2
Inputs:  E[x] = 5.03, Var[x] = 1.72
Results:  μ = 1.5825,  σ = 0.2565

Memory Registers:
R1 = μ
R2 = σ
R3 = E[x]
R4 = Var[x]


Source

"Log-normal distribution"  Wikipedia.  Last Edited May 18, 2023 and retrieved May 24, 2023.  https://en.wikipedia.org/wiki/Log-normal_distribution

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. 

Saturday, May 13, 2023

HP 12C Using TVM variables as Registers

 HP 12C Using TVM variables as Registers



Special Thanks

Regarding the HP 12C Tips talk I gave on HHC 2017, I received this tip from an email from   SergioSamy.   Appreciation and gratitude.  


To watch my HP 12C tip presentation, click here:

https://www.youtube.com/watch?v=Q54UbDzpAIw




Why Use TVM Variables?


Normally, we use the variables n, i, PV, PMT, and FV for time value of money, cash flow, and depreciation calculations.  They can be used for variables for non-finance or other business calculations as well.


When we program on the Classic HP 12C, we have 99 steps.  If the program memory is clear, we have 20 registers from R.9  (register dot-nine) to R0 (register zero).   For every eight steps, a memory register is lost.   


At full capacity of the Classic HP 12C, we only have seven registers left (R0 through R6).  


The moment that we use press the [ Σ+ ] button and use statistics, the registers R1 and R6 get occupied, possibly leaving R0 to use for other purposes:


R1 = n

R2 = Σx

R3 = Σx^2

R4 = Σy

R5 = Σy^2

R6 = Σxy


However, the TVM registers: n, i, PV, PMT, and FV, are permanent memory registers for use.   Today's programs will illustrate this use.   


Note:  Pressing the TVM keys once after a number (key word: after) stores the number in a variable.   If you don't key a number first, then the program solves for the a variable.  Let's look at a couple of examples.



Economic Ordering Quantity


Formula:


EOQ = √(2 * CPO * SLS ÷ (CPU * HOLD%))


CPO = fixed order cost

SLS = number of project sales units

CPU = variable cost per unit

HOLD% = projected cost of holding inventory

EOQ = economic ordering quantity, in units


TVM variables used:


[ n ]:  EOQ, computed

[ i ]: HOLD%,  entered

[ PV ]:  CPU, entered

[ PMT ]:  CPO, entered

[ FV ]:  SLS, entered



Program Code:


Line Number:  Key Code;  Key


01:  45, 14;  RCL PMT

02:  45, 15;  RCL FV

03:  20;  ×

04:  2;  2

05:  20;  ×

06:  45, 13;  RCL PV

07:  45, 12;  RCL i

08:  25;  %

09:  34;  x<>y

10:  33;  R↓

11:  10;  ÷

12:  43, 21;  √

13:  44, 11;  STO n

14:  43,33,00;  GTO 00



Example


CPO = 40.95

SLS = 8,000

CPU = 5.50

HOLD% = 10%


10 [ i ]

5.50 [ PV ]

40.95  [ PMT ]

8000 [ FV ]

[ R/S ].  Result:  1091.45


Source


HP-17B, HP-19B, HP-27S  Step-by-Step Solutions For Your HP Calculator.  Marketing and Sales.   Hewlett Packard.  Edition 1.  January 1988



Quadratic Equation


Instructions:


Find the roots of a*x^2 + b*x + c = 0


The program ends with the discriminant stored in R0. 


D = b^2 - 4*a*c


If D<0, the roots are complex in the form of s ± ti:

s:  real part, stored in PMT

t:  imaginary part, stored in FV


If D≥0, the roots are real and:

Root 1 is stored in PMT

Root 2 is stored in FV


Store a in [ n ], b in [ i ], and c [ PV ].  Then run the program. 


Note:  to get the absolute value, square then take the square root of the number.  This is why I have two square root commands in a row: one is to make the absolute value; the second to take the square root of D. 


Program Code:


Line Number:  Key Code;  Key


01:  45,12;  RCL I

02:  2;  2

03:  21;  y^x

04:  45, 13;  RCL PV

05:  45, 11;  RCL n

06:  20;  ×

07:  4;  4

08:  20;  ×

09:  30;  -

10:  44, 0;  STO 0

11:  45, 12;  RCL i

12:  16;  CHS

13:  2;  2

14:  10;  ÷

15:  45, 11;  RCL n

16:  10;  ÷

17:  44, 14;  STO PMT

18:  45, 0;  RCL 0

19:  2;  2

20:  21;  y^x

21:  43, 21;  √

22:  43, 21;  √

23:  2;  2

24:  10;  ÷

25:  45, 11;  RCL n

26:  10;  ÷

27:  44, 15;  STO FV

28:  0;  0

29:  45, 0;  RCL 0

30:  43, 34;  x≤y

31:  43,33,00;  GTO 00

32:  45,14;  RCL PMT

33:  36;  ENTER

34:  36;  ENTER

35:  45, 15;  RCL FV

36:  30;  -

37:  44, 15; RCL FV

38:  33; R↓

39:  43, 36;  LSTx

40:  40;  +

41:  44,14; STO PMT

42:  45, 0;  RCL 0

43:  43,33,00;  GTO 00


Examples


2*x^2 - 3*x + 6 = 0


2 [ n ]

-3 [ i ] 

6 [ PV ]

[ R/S ]


Results:

D = -39.00   (complex roots)

[ RCL ] [ PMT ]:  Real part:  0.75

[ RCL ] [ FV ]:  Imaginary part:  1.56

0.75 ± 1.56i


x^2 + 8*x - 4 = 0


1 [ n ]

8 [ i ] 

-4 [ PV ]

[ R/S ]


Results:

D = 80

[ RCL ] [ PMT ]:  Root 1:  0.47

[ RCL ] [ FV ]:  Root 2:  -8.47

0.47, -8.47



Hope you find this tip helpful,


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. 


Spotlight: Calculated Industries QR Calc

Spotlight: Calculated Industries QR Calc <Title> Quick Facts Model: 3375 Name: QR Calc Company: Calculated Industries ...