29
Page 1 of 29 Expanding the HP 12C Edward Shore Introduction The HP 12C calculator is an excellent financial calculator. The programming capability allows us to enter algorithms for various applications. Even without the trigonometric functions, we can still use the HP 12C to use it in a wide variety of applications, including scientific. This talk will explore programming tips and other applications. Contents Assumptions.................................................................................................................................................. 2 Quick Mathematical Tips .............................................................................................................................. 2 Arithmetic ................................................................................................................................................. 2 Mathematical Functions ........................................................................................................................... 2 How to Enter π .......................................................................................................................................... 3 Example: Surface Area and Volume of a Sphere ..................................................................................... 3 How Many Inputs do I have? ........................................................................................................................ 5 Flag and Choice Setting with the x=0 test ..................................................................................................... 5 Example: US to SI Conversions ................................................................................................................. 5 Use of Statistic Variables............................................................................................................................... 7 Example 1: Sum of f(x) ............................................................................................................................. 7 Example 2: Simple Logistic Curve Fitting ................................................................................................. 8 Two-Round Subroutines ............................................................................................................................... 9 HP 12 Subroutine Example ....................................................................................................................... 9 HP 12C Derivative Approximation .......................................................................................................... 10 Applications and Examples ......................................................................................................................... 12 Solving 2 x 2 Systems .............................................................................................................................. 12 Quadratic Equations ............................................................................................................................... 13 Ulam’s Conjecture................................................................................................................................... 15 Greatest Common Divisor ....................................................................................................................... 16 Taxes: Gross Up Calculations ................................................................................................................. 17 Cash Flows: Net Present Value, Net Future Value, and Net Utility Stream ........................................... 18 Projectile Motion, No Air Resistance: Maximum Distance (U.S. Units) ................................................. 20 Geometric Areas: Right Triangle, Circle, Ellipse ..................................................................................... 22 Conversion from Binary to Decimal ........................................................................................................ 23 Conversion from Decimal to Binary ........................................................................................................ 24 Coordinate locator using length (r) and pitch (% of slope) ..................................................................... 25

Expanding the HP 12C...Page 1 of 29 Expanding the HP 12C Edward Shore Introduction The HP 12C calculator is an excellent financial calculator. The programming capability allows us

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

  • Page 1 of 29

    Expanding the HP 12C Edward Shore

    Introduction The HP 12C calculator is an excellent financial calculator. The programming capability allows us to enter algorithms for various applications. Even without the trigonometric functions, we can still use the HP 12C to use it in a wide variety of applications, including scientific. This talk will explore programming tips and other applications.

    Contents Assumptions .................................................................................................................................................. 2

    Quick Mathematical Tips .............................................................................................................................. 2

    Arithmetic ................................................................................................................................................. 2

    Mathematical Functions ........................................................................................................................... 2

    How to Enter π .......................................................................................................................................... 3

    Example: Surface Area and Volume of a Sphere ..................................................................................... 3

    How Many Inputs do I have? ........................................................................................................................ 5

    Flag and Choice Setting with the x=0 test ..................................................................................................... 5

    Example: US to SI Conversions ................................................................................................................. 5

    Use of Statistic Variables ............................................................................................................................... 7

    Example 1: Sum of f(x) ............................................................................................................................. 7

    Example 2: Simple Logistic Curve Fitting ................................................................................................. 8

    Two-Round Subroutines ............................................................................................................................... 9

    HP 12 Subroutine Example ....................................................................................................................... 9

    HP 12C Derivative Approximation .......................................................................................................... 10

    Applications and Examples ......................................................................................................................... 12

    Solving 2 x 2 Systems .............................................................................................................................. 12

    Quadratic Equations ............................................................................................................................... 13

    Ulam’s Conjecture ................................................................................................................................... 15

    Greatest Common Divisor ....................................................................................................................... 16

    Taxes: Gross Up Calculations ................................................................................................................. 17

    Cash Flows: Net Present Value, Net Future Value, and Net Utility Stream ........................................... 18

    Projectile Motion, No Air Resistance: Maximum Distance (U.S. Units) ................................................. 20

    Geometric Areas: Right Triangle, Circle, Ellipse ..................................................................................... 22

    Conversion from Binary to Decimal ........................................................................................................ 23

    Conversion from Decimal to Binary ........................................................................................................ 24

    Coordinate locator using length (r) and pitch (% of slope) ..................................................................... 25

  • Page 2 of 29

    Combination/Binomial Distribution/Negative Binomial Distribution ..................................................... 27

    Conclusion ................................................................................................................................................... 29

    Assumptions The presentation and these notes assume that we are using the classic (regular) edition. For the most part, the classic HP 12C and the HP 12C Platinum are the same. However, there are several differences that need to be addressed: Programming Capacity. The classic HP 12C has 99 programming steps and 10 storage registers. In

    programming each step has two digits (01 to 99). The HP 12C Platinum has a capacity of 400 steps (the step numbers have three digits) with up to 20 registers. However, the more program steps, the less memory registers available (the minimum is 7).

    Arithmetic Operation Setting. The classic HP 12C has RPN (reverse polish notation), while the HP 12C Platinum has both RPN and algebraic. All programs in this presentation are set in RPN mode.

    Step Markers. The classic HP 12C has two digit step markers (00-99), while the HP 12C Platinum has three digit step markers (000-400). The difference comes into play when using the GTO (go to) command.

    Last X. The location of last X command is in different locations. On the classic HP 12C, LST X is located on the ENTER key (code 43, 36), while the HP 12C Platinum is located on the plus key (code 43, 40).

    No trigonometric functions are used. Everything is rounded to 2 decimal places, with Fix 2 mode set ([ f ], [ 2 ]). The accuracy of the programs were based on Fix 2 mode.

    Quick Mathematical Tips

    Arithmetic Multiplying by 100: [ENTER], 1, [xy], [%T] Example: 7.28, [ENTER], 1, [xy], [%T] returns 728 One key stroke less than [ENTER], 1, 0, 0, [ * ] Dividing by 100: [ENTER], 1, [ % ] Example: 283, [ENTER], 1, [ % ] returns 2.83 Two key strokes less than [ENTER], 1, 0, 0, [ ÷ ]

    Mathematical Functions Absolute Value: 2, [y^x], [ g ] ( √ ) Example: -13.3, [ENTER], 2, [y^x], [ g ] ( √ ) returns 13.03

  • Page 3 of 29

    Sign Function: [ENTER], [ENTER], 2, [y^x], [ g ] ( √ ), [ ÷ ] Example 1: -28, [ENTER], [ENTER], 2, [y^x], [ g ] ( √ ), [ ÷ ] returns -1 Example 2: 28, [ENTER], [ENTER], 2, [y^x], [ g ] ( √ ), [ ÷ ] returns 1 Modulus of two positive numbers (a mod b): a, [ENTER], b, [ ÷ ], [ g ] (LSTx), [ xy ], [ g ] (FRAC), [ * ] Example: a = 43, b = 7, 43 mod 7. 43, [ENTER], 7, [ ÷ ], [ g ] (LSTx), [ xy ], [ g ] (FRAC), [ * ] returns 1 Number of Digits of an integer: [ g ] (LN), [EEX], 1, [ g ] (LN), [ ÷ ], [ g ] (INTG), 1, [ + ] Example: 12345, [ g ] (LN), [EEX], 1, [ g ] (LN), [ ÷ ], [ g ] (INTG), 1, [ + ], returns 5. Note that I used [EEX] 1 to create 10. We could type 10 and the number of key strokes would be the same.

    How to Enter π The HP 12C does not have a π button, we’ll have to enter π manually or use an approximation. Using the 10 digit approximation 3.1415965359.

    This will take 11 steps, one for each digit and the decimal point.

    We can use the approximation π ≈ 355/113. 355/113 = 3.14159292035 355/113 approximates π to 5 decimal places. This takes 8 steps: 3, 5, 5, [ENTER], 1, 1, 3, [ ÷ ] Richard Nelson suggests this memory aid: take the first three odd digits twice (113355), divide

    last three by first three (355/113).

    Also, we can use the approximation π ≈ 22/7 22/7 = 3.14285714286 22/7 approximates π accurately to 3 places. This takes 5 steps: 2, 2, [ENTER], 7, [ ÷ ]

    In this presentation, I use the 355/113 approximation for π. I find this the perfect balance between accuracy and the number of steps. One word of caution, using a fractional approximation can maintain accuracy for a few decimal places. Also the more complex the operation, the more round off error is encountered.

    Example: Surface Area and Volume of a Sphere This program calculates the surface area and volume of a sphere give the radius r. Again we take 355/113 as an approximation for π. The well-known formulas: S = 4*π*r^2 V = 4/3*π*r^3 = S * r/3

    Step Code Key Notes

    01 44, 0 STO 0 Store radius in R0

  • Page 4 of 29

    02 2 2 Calculate surface volume

    03 21 Y^X

    04 4 4

    05 20 *

    06 3 3 Enter π

    07 5 5

    08 5 5

    09 36 ENTER

    10 1 1

    11 1 1

    12 3 3

    13 10 ÷

    14 20 *

    15 31 R/S Display surface volume

    16 3 3 Calculate volume

    17 10 ÷

    18 45, 0 RCL 0

    19 20 *

    20 43, 33, 00 GTO 00 Display volume, stop program execution

    Registers used: R0 = r Input: Enter radius, r, and press [R/S]. Output: Obtain the approximate surface area. Press [R/S] for the volume. Examples: Radius = 2. Surface area ≈ 50.27, Volume ≈ 33.51 Radius = 8.64. Surface area ≈ 938.07, Volume ≈ 2701.65 Fun fact: A sphere of radius 3 will have the same surface area and volume, at approximately 113.09734.

  • Page 5 of 29

    How Many Inputs do I have? There are three ways to generate inputs:

    Loading the stack before executing the program. This is useful when you have only one input.

    Prompt for the inputs using the [R/S].

    Store all the required inputs in the registers before execution. This is my preferred method when I have 3 or more inputs.

    Flag and Choice Setting with the x=0 test You can branch a program by designating a flag variable. You can designate a register of your choice. For this technique, I prefer R0. This is useful for providing several functions without the need to memorize specific line numbers, setting monthly vs. yearly payments, or deciding which conversion is needed. Depending on the size of the program, 2 to 4 choices could fit within program memory of the classic HP 12C. General algorithm: RCL [register number] [test value] - X=0 GTO [appropriate line number] (repeat until you are down to the last two choices) RCL [register number] [test value n-1] - X=0 GTO [line number for choice n-1] GTO [line number for choice n]

    Example: US to SI Conversions The program will require two inputs: the value to be converted and a number that designates the following conversion: Choice 0: lb to kg, ÷ 2.2046 Choice 1: in to cm, * 2.54 Choice 2: gal to L, * 3.7854 Choice 3: mi to km, * 1.6093 For example, to convert 18 miles to kilometers, type 18, [ENTER], 3, [R/S]. 3 is stored in the choice variable. (Result: 28.97 km). In this program the choice variable (flag) is stored in R0.

  • Page 6 of 29

    Program:

    Step Code Key Notes

    01 44, 0 STO 0 Store choice variable in R0

    02 34 XY

    03 44, 1 STO 1 Store value to be converted in R1

    04 34 XY

    05 43, 35 X=0 Conversion: lb to kg?

    06 43, 33, 18 GTO 18

    07 45, 0 RCL 0 Conversion: in to cm?

    08 1 1

    09 30 -

    10 43, 35 X=0?

    11 43, 33, 27 GTO 27

    12 45, 0 RCL 0 Conversion: gal to L?

    13 2 2

    14 30 -

    15 43, 35 X=0

    16 43, 33, 34 GTO 34

    17 43, 33, 43 GTO 43 Conversion: mi to km?

    18 45, 1 RCL 1 Conversion: lb to kg, flag = 0

    19 2 2

    20 48 .

    21 2 2

    22 0 0

    23 4 4

    24 6 6

    25 10 ÷

    26 43, 33, 00 GTO 00

    27 45, 1 RCL 1 Conversion: in to cm, flag = 1

    28 2 2

    29 48 .

    30 5 5

    31 4 4

    32 20 *

    33 43, 33, 00 GTO 00

    34 45, 1 RCL 1 Conversion: gal to L, flag = 2

    35 3 3

    36 48 .

    37 7 7

    38 8 8

    39 5 5

    40 4 4

    41 20 *

    42 43, 33, 00 GTO 00

    43 45, 1 RCL 1 Conversion: mi to km, flag = 3

    44 1 1

    45 48 .

    46 6 6

    47 0 0

    48 9 9

    49 3 3

    50 20 *

    51 43, 33, 00 GTO 00

  • Page 7 of 29

    Use of Statistic Variables We are able to use statistical functions, such as x^ and Σ+ in programs. This will allow us to take advantage of statistical registers. The cost is that six variables will be used (R1 to R6). This leaves only four variables for inputs and outputs (R0, R7, R8, R9) Statistics Variables

    R1: n R4: Σy

    R2: Σx R5: Σy^2

    R3: Σx^2 R6: Σxy

    Example 1: Sum of f(x) Σ f(x) R0 = a/x, R7 = b; result R2 = Σx, sum Function starts at step 15 and ends with GTO 02. Template:

    Step Code Key Notes

    01 43, 33, 15 GTO 15 Calculate f(x)

    02 49 Σ+ Add result, return point

    03 1 1 Increase R0 by 1, counter

    04 44, 40, 0 STO+ 0

    05 45, 0 RCL 0 Recall counter (R0)

    06 45, 7 RCL 7 Recall upper limit (R7)

    07 1 1

    08 40 +

    09 30 -

    10 43, 35 X=0 Test: Is counter = upper limit + 1 Has the counter exceed the upper limit

    11 43, 33, 13 GTO 13 Yes: Go to the end of the program

    12 43, 33, 01 GTO 01 No: Start the loop again

    13 45, 2 RCL 2 Recall Σ

    14 43, 33, 00 GTO 00 Stop Execution

    15 f(x), use R0 … Start f(x) here, use R0 as x

    (last step) 43, 33, 02 GTO 02

    Example: Σ x^2 – 2*x = Σ x * (x – 1)

    Step Code Key Notes

    01 43, 33, 15 GTO 15 Calculate f(x)

    02 49 Σ+ Add result, return point

    03 1 1 Increase R0 by 1, counter

    04 44, 40, 0 STO+ 0

    05 45, 0 RCL 0 Recall counter (R0)

    06 45, 7 RCL 7 Recall upper limit (R7)

    07 1 1

    08 40 +

    09 30 -

    10 43, 35 X=0 Test: Is counter = upper limit + 1 Has the counter exceed the upper limit

    11 43, 33, 13 GTO 13 Yes: Go to the end of the program

    12 43, 33, 01 GTO 01 No: Start the loop again

  • Page 8 of 29

    Step Code Key Notes

    13 45, 2 RCL 2 Recall Σ

    14 43, 33, 00 GTO 00 Stop Execution

    15 45, 0 RCL 0 Start f(x) here, use R0 as x

    16 36 ENTER

    17 36 ENTER

    18 2 2

    19 30 -

    20 20 *

    21 43, 33, 02 GTO 02 Finish with GTO 02.

    Example 2: Simple Logistic Curve Fitting Curve: y = 1 / (b + m*e^(-x)) Transformation: X’ = e^(-X), Y’ = 1/Y L.R. function on the 12C: Intercept: 0, [ g ] (y^) Slope (from intercept): 1, y^, xy, R↓, xy, - Instructions: 1. Clear statistical registers. Press [ f ], [CLx] (CLEAR REG) 2. Data: y, [ENTER], x, [R/S] 3. For the intercept and slope: GTO 08, R/S, A is displayed, R/S, B is displayed

    Step Code Key Notes

    01 16 CHS Enter data

    02 43, 22 e^x Adjust X: e^-x

    03 34 xy

    04 22 1/x Adjust Y: 1/y

    05 34 xy

    06 49 Σ+ Enter data point, n is displayed

    07 43, 33, 00 GTO 00 Stop program execution

    08 0 0 Calculate b

    09 43, 2 y^

    10 44, 7 STO 7

    11 31 R/S Display b

    12 1 1 Calculate m

    13 43, 2 y^

    14 34 xy

    15 33 R↓

    16 34 xy

    17 30 -

    18 44, 8 STO 8

    19 43, 33, 00 GTO 00 Display m

    Example:

    X 0.5 1.0 1.5 2.0 2.5

    Y 0.384 0.422 0.450 0.468 0.480

    Results: b = 2.00, m = 0.99 (Fix 2). y = 1/(2 + 0.99*e^(-x))

  • Page 9 of 29

    Two-Round Subroutines The HP 12C does not have subroutine commands, but you can simulate subroutines. Here is one way to do it, if you know the subroutine will be used twice: It is very important you plan your program in advance, with line numbers. Marking the line numbers will facilitate where the subroutine and return markings will be located.

    1. Designate a register as a flag variable. Store 1 in the flag variable. 2. Enter the main portion of the program. Determine where the subroutine will be called. 3. Follow the subroutine call with the roll down command (R↓). 4. At the end of the subroutine, recall the flag variable. 5. Determine which round it is by recalling the flag variable. First round: flag = 1. Second round:

    flag = 0. Use the test x=0. If it passes, send the pointer to the second R↓. If it fails, subtract 1 from the flag variable and send the pointer to the first R↓.

    The following examples will illustrate this method.

    HP 12 Subroutine Example Let f(x) = g^2(x) / (1 + g(x)) Where g(x) = x^2 – 1

    Step Code Key Notes

    01 44, 0 STO 0 Store x in R0

    02 1 1

    03 44, 2 STO 2 Store flag variable

    04 45, 0 RCL 0 Set up for subroutine round 1

    05 43, 33, 19 GTO 19

    06 33 R↓ 1st return point

    07 2 2

    08 21 Y^X g^2(x)

    09 44, 1 STO 1 Store immediate result

    10 45, 0 RCL 0 Set up for subroutine round 2

    11 43, 33, 19 GTO 19

    12 33 R↓ 2nd return point

    13 1 1

    14 40 + 1 + g(x)

    15 45, 1 RCL 1

    16 34 XY

    17 10 ÷

    18 43, 33, 00 GTO 00 Stop execution

    19 2 2 Start subroutine, g(x)

    20 21 Y^X

    21 1 1

    22 30 -

    23 45, 2 RCL 2 Recall flag variable

    24 43, 35 X=0 Are we in round 2?

    25 43, 33, 12 GTO 12 If yes, go to 2nd return point

    26 1 1 Otherwise, decrease flag variable

    27 44, 30, 2 STO- 2

    28 33 R↓ Set up display

    29 43, 33, 06 GTO 06 Go to 1st return point

  • Page 10 of 29

    Variables used: R0 = x (input), R1 = flag variable, R2 = temp storage/result Example 1: x = 1.00, Result: 0.00 Example 2: x = 8.36, Result: 67.90 Example 3: x = -2.81, Result: 6.02

    HP 12C Derivative Approximation Approximate the derivative: f’(x) ≈ (f(x + h) – f(x))/h where h = 10^-5 Customize f(x). The function f(x) starts at line 22 with x+h or x on the stack. The GTO statements remain constant regardless of f(x). Up to 71 steps are available for f(x). In the program listing provided below, I provide f(x) = x^2*e^x.

    Step Key Code Notes

    01 44, 0 STO 0 Store x in R0

    02 1 1

    03 44, 3 STO 3 Set up flag variable, 2 subroutine rounds

    04 1 1

    05 26 EEX

    06 5 5

    07 16 CHS

    08 44, 1 STO 1 Store h in R1

    09 45, 0 RCL 0

    10 45, 1 RCL 1

    11 40 + x+ h

    12 43, 33, 23 GTO 23 Subroutine: 1st round

    13 33 R↓ Return: 1st round

    14 44, 2 STO 2 Store temp result, f(x + h)

    15 45, 0 RCL 0 x

    16 43, 33, 23 GTO 23 Subroutine: 2nd round

    17 33 R↓

    18 44, 30, 2 STO- 2 f(x+h) – f(x)

    19 45, 2 RCL 2

    20 45, 1 RCL 1

    21 10 ÷ (f(x+h) – f(x))/h

    22 43, 33, 00 GTO 00 Stop execution

    23 36 ENTER Subroutine begins here, f(x)

    24 36 ENTER

    25 2 2

    26 21 Y^X

    27 34 XY

    28 43, 22 e^x

    29 20 * End of f(x)

    30 45, 3 RCL 3 Need the next 7 steps to the end of f(x) – Check flag variable

    31 43, 35 X=0

    32 43, 33, 17 GTO 17 Are we in round 2?

    33 1 1 If yes, go to 2nd return point

  • Page 11 of 29

    34 44, 30, 3 STO- 3 Otherwise, decrease flag variable

    35 33 R↓ Set up display

    36 43, 33, 13 GTO 13 Go to 1st return point

    Example 1: x = 1.00. Result: 8.16 Example 2: x = 3.34. Result: 503.68 (approximate) Example 3: x = 6.10. Result: 22030 (should be 22029.83) Template for the derivative below:

    Step Key Code Notes

    01 44, 0 STO 0 Store x in R0

    02 1 1

    03 44, 3 STO 3 Set up flag variable, 2 subroutine rounds

    04 1 1

    05 26 EEX

    06 5 5

    07 16 CHS

    08 44, 1 STO 1 Store h in R1

    09 45, 0 RCL 0

    10 45, 1 RCL 1

    11 40 + x+ h

    12 43, 33, 23 GTO 23 Subroutine: 1st round

    13 33 R↓ Return: 1st round

    14 44, 2 STO 2 Store temp result, f(x + h)

    15 45, 0 RCL 0 x

    16 43, 33, 23 GTO 23 Subroutine: 2nd round

    17 33 R↓

    18 44, 30, 2 STO- 2 f(x+h) – f(x)

    19 45, 2 RCL 2

    20 45, 1 RCL 1

    21 10 ÷ (f(x+h) – f(x))/h

    22 43, 33, 00 GTO 00 Stop execution

    23 Subroutine begins here, f(x)

    … …

    End of f(x)

    nn 45, 3 RCL 3 Need the next 7 steps to the end of f(x) – Check flag variable

    nn 43, 35 X=0

    nn 43, 33, 17 GTO 17 Are we in round 2?

    nn 1 1 If yes, go to 2nd return point

    nn 44, 30, 3 STO- 3 Otherwise, decrease flag variable

    nn 33 R↓ Set up display

    nn 43, 33, 13 GTO 13 Go to 1st return point

  • Page 12 of 29

    Applications and Examples

    Solving 2 x 2 Systems R4 * x + R5 * y = R6 R1 * x + R2 * y = R3 Calculations: R0 = R4 * R2 – R5 * R1 x = (R2 * R6 – R5 * R3)/R0 y = (R4 * R3 – R1 * R6)/R0 Program:

    Step Code Key Notes

    01 45, 4 RCL 4 Start with all the values stored in R1 – R6. Calculate determinant which will be stored in R0.

    02 45, 2 RCL 2

    03 20 *

    04 45, 5 RCL 5

    05 45, 1 RCL 1

    06 20 *

    07 30 -

    08 44, 0 STO 0

    09 34 R/S Display determinant of [[R4, R5][R1, R2]]. If the determinant is 0, then stop. There is no solution.

    10 45, 2 RCL 2 Calculate x

    11 45, 6 RCL 6

    12 20 *

    13 45, 5 RCL 5

    14 45, 3 RCL 3

    15 20 *

    16 30 -

    17 45, 0 RCL 0

    18 10 ÷

    19 44, 7 STO 7

    20 31 R/S Display x

    21 45, 4 RCL 4 Calculate y

    22 45, 3 RCL 3

    23 20 *

    24 45, 1 RCL 1

    25 45, 6 RCL 6

    26 20 *

    27 30 -

    28 45, 0 RCL 0

    29 10 ÷

    30 44, 8 STO 8

    31 43, 33, 00 GTO 00 Display y

    Example: Solve the system 2 * x + 4 * y = 18 and 3* x – 2* y = 3 Results: Determinant of [[2, 4] [3, -2]] = 16, x = 3, y = 3

  • Page 13 of 29

    Quadratic Equations R1*x^2 + R2*x + R3 = 0 If R0 < 0, then R4 = real part, R5 = +/- imaginary part If R0 > 0, then R4, R5 are the two real roots R0 = R2^2 – 4 * R1 * R3

    Step Code Key Notes

    01 45, 2 RCL 2 Start with values stored in R1, R2, R3. Calculate discriminant.

    02 36 ENTER

    03 20 *

    04 45, 1 RCL 1

    05 45, 3 RCL 3

    06 20 *

    07 4 4

    08 20 *

    09 30 -

    10 44, 0 STO 0

    11 31 R/S Display discriminant which is stored in R0.

    12 0 0

    13 43, 34 X≤Y Is 0 ≤ R0?

    14 43, 33, 32 GTO 32 If so, go to step 32.

    15 45, 1 RCL 1 Complex Roots: real part

    16 36 ENTER

    17 40 +

    18 45, 2 RCL 2

    19 16 CHS

    20 34 XY

    21 10 ÷

    22 44, 4 STO 4

    23 31 R/S

    24 43, 36 LSTx Complex Roots: imaginary part

    25 45, 0 RCL 0

    26 16 CHS

    27 43, 21 √

    28 34 XY

    29 10 ÷

    30 44, 5 STO 5

    31 43, 33, 00 GTO 00 Stop execution

    32 45, 2 RCL 2 Real root calculations

    33 16 CHS

    34 45, 0 RCL 0

    35 43, 21 √

    36 40 +

    37 45, 1 RCL 1

    38 36 ENTER

    39 40 +

    40 10 ÷

    41 44, 4 STO 4

    42 31 R/S Real root 1

    43 43, 36 LSTx

  • Page 14 of 29

    Step Code Key Notes

    44 45, 2 RCL 2

    45 45, 0 RCL 0

    46 43, 21 √

    47 40 +

    48 16 CHS

    49 34 XY

    50 10 ÷

    51 44, 5 STO 5

    52 43, 33, 00 GTO 00 Real root 2

    Example 1: -2 * x^2 + 3 * x + 3 = 0 (R1 = -2, R2 = 3, R3 = 3) Outputs: R0 = 33; real roots: 2.19, -0.69 Example 2: -2 * x^2 + 3 * x - 3 = 0 (R1 = -2, R2 = 3, R3 = -3) Outputs: R0 = -15; real part: .75, imaginary part: -.97 (roots: .75 +/- .97i)

  • Page 15 of 29

    Ulam’s Conjecture Determine how many steps it takes an integer n to get to 1 using the following steps: If n is even: divide n by 2 If n is odd: multiply n by 3 and add 1 Input: n (stored in RO) Output: number of steps (stored in R1) Program:

    Step Code Key Notes

    01 44, 0 STO 0 Store n in R0

    02 0 0

    03 44, 1 STO 1 Initialize the number of steps in R1

    04 45, 0 RCL 0 Check to see if n is even, main loop starts here

    05 2 2

    06 10 ÷

    07 43, 24 FRAC

    08 43, 35 X=0

    09 43, 33, 16 GTO 16 If n is even, go to step 16

    10 3 3 If n is odd

    11 44, 20, 0 STO* 0

    12 1 1

    13 44, 40, 0 STO+ 0 Store result in n for the next loop

    14 44, 40, 1 STO+ 1 Increment the counter

    15 43, 33, 20 GTO 20

    16 2 2 Divide even n by 2, store the result

    17 44, 10, 0 STO÷ 0

    18 1 1 Increment the counter

    19 44, 40, 1 STO+ 1

    20 45, 0 RCL 0 Is the result = 1?

    21 1 1

    22 30 -

    23 43, 35 X=0

    24 43, 33, 26 GTO 26 If the result = 1, go to the end of the program

    25 43, 33, 04 GTO 04 If not, start the loop again

    26 45, 1 RCL 1

    27 43, 33, 00 GTO 00

    Examples: The path from 69 to 1 takes 14 steps. The path from 84 to 1 takes 9 steps.

  • Page 16 of 29

    Greatest Common Divisor This program calculates the greatest common divisor of two integers. You can enter the two integers in either order. Program:

    Step Code Key Notes

    01 43, 34 X≤Y Determine which integer is greater

    02 34 XY

    03 44, 1 STO 1 R1 = max(X,Y)

    04 34 XY

    05 44, 0 STO 0 R0 = min(X,Y)

    06 45, 1 RCL 1 Begin Euclidian division routine

    07 45, 1 RCL 1 Recall R1 twice

    08 45, 0 RCL 0

    09 10 ÷ Divide R1 by R0

    10 43, 25 INTG int(R1/R0)

    11 45, 0 RCL 0

    12 20 *

    13 30 - Calculate remainder: remainder = int(R1/R0) * R0 – R1

    14 43, 35 X=0 Is remainder = 0?

    15 43, 33, 21 GTO 21 If yes, go to the end

    16 34 XY If not, set up for the next loop

    17 44, 1 STO 1 Old min becomes new max, R0 → R1

    18 34 XY

    19 44, 0 STO 0 Store new min

    20 43, 33, 06 GTO 06 Start Euclidian division routine again

    21 45, 0 RCL 0 End Result: display GCD

    22 43, 33, 00 GTO 00 Stop execution

    Input: integer [ENTER] integer [R/S] Result: GCD Test 1: GCD(142,25) Input: 142 [ENTER] 25 [R/S] Result: 1 Test 2: GCD(2555, 1365). Result: 35

  • Page 17 of 29

    Taxes: Gross Up Calculations We have to pay a person, and the person lives outside of your tax jurisdiction (outside of your state or the United States). Tax withholding may be required. However, you or someone else that is requesting the payment wants the face amount. In order to give the face amount and fulfill the tax requirement at the same time, the payment is must be grossed up. Formulas: Gross up Amount = Face Amount/(1 – Tax Rate%) Amount of Tax = Gross up Amount – Face Amount Program:

    Step Code Key Notes

    01 44, 0 STO 0 Store Tax Rate

    02 34 XY

    03 44, 1 STO 1 Store Face Value

    04 45, 0 RCL 0

    05 1 1

    06 25 %

    07 1 1

    08 30 -

    09 16 CHS

    10 45, 1 RCL 1

    11 34 XY

    12 10 ÷

    13 31 R/S Display Gross up Amount

    14 45, 1 RCL 1

    15 30 -

    16 43, 33, 00 GTO 00 Display Tax

    Input: face value, [R/S], tax rate, [R/S] Result: gross amount, [R/S], tax Part 1: Face Value: $1,000, Tax Rate: 30%. Input: 1000 [R/S], 30 [R/S] Result: 1428.57 [R/S], 428.57 [R/S] The gross up amount is $1,428.57 (total amount to be paid), and corresponding tax is $428.57. Part 2: Face Value: $2,500, Tax Rate: 7%. Input: 2500 [R/S], 7 [R/S] Result: 2688.17 [R/S], 188.17 [R/S] The gross up amount is $2,688.17 (total amount to be paid), and corresponding tax is $188.17.

  • Page 18 of 29

    Cash Flows: Net Present Value, Net Future Value, and Net Utility Stream Initialization Steps:

    1. Clear the registers/finance registers 2. Press [ g ] (GTO) 00 to get the pointer to line 00. (000 for the HP 12C Platinum

    editions. Remember, the Platinum editions have up to 400 steps and line numbers are in triple digits)

    3. Store -1 in [ n ] (don’t worry, n is incremented in the main loop) 4. Store periodic interest rate in [ i ]. 5. Store 0 in register 0 (0 [STO] [ 0 ]). Register 0 is use for calculating NPV

    Enter each cash flow one at a time, and press [R/S]. Ready to calculate:

    1. Press [ g ] (GTO) 10 (or 010) to get the pointer to line 10. 2. Press [R/S] to get NPV (net present value) 3. Press [R/S] to get NFV (net future value) 4. Press [R/S] to get NUS (net utility stream)

    Program:

    Step Code Key Notes

    01 16 CHS Main loop starts here, input data

    02 15 FV Calculate PV of each cash flow

    03 45, 11 RCL n

    04 1 1

    05 40 +

    06 11 N

    07 13 PV

    08 44, 40, 0 STO+ 0

    09 43, 33, 0 GTO 00 Finish main loop

    10 45, 0 RCL 0 Calculate NPV

    11 31 R/S Display NPV

    12 1 1 Calculate NFV

    13 16 CHS

    14 13 PV

    15 0 0

    16 14 PMT

    17 15 FV

    18 45, 0 RCL 0

    19 20 *

    20 31 R/S Display NFV

    21 45, 0 RCL 0 Calculate NUS

    22 1 1

    23 16 CHS

    24 14 PMT

    25 0 0

    26 15 FV

    27 13 PV

    28 10 ÷

  • Page 19 of 29

    Step Code Key Notes

    29 43, 33, 0 GTO 00 Display NUS

    Example: Rate: 15%

    Cash Flow # Flow

    0 -10,000.00

    1 2,500.00

    2 3,500.00

    3 5,000.00

    4 5,000.00

    Input: [ f ] CLEAR FIN, [ f ] CLEAR PRGM -1 [ n ] // do this on each new problem 0 [STO] [ 0 ] // do this on each new problem 15 [ i ] 10000 [CHS] [R/S] 2500 [R/S] 3500 [R/S] 5000 [R/S] 5000 [R/S] Results: [GTO] 10 [R/S]: NPV = 966.76 [R/S]: NFV = 1690.88 [R/S]: NUS = 338.62 Input slowly and carefully.

  • Page 20 of 29

    Projectile Motion, No Air Resistance: Maximum Distance (U.S. Units) For an object that travels in a projectile motion, we can track its range (distance traveled from the beginning) and height by: R = v^2 * sin (2 * θ)/g H = (v^2 * (sin θ)^2) / (2 * g) Where: v = initial velocity θ = initial angle g = Earth’s gravity. For in US units, g = 32.1740468 ft/s^2. This program uses the approximation g ≈ 32.174 ft/s^2 The projectile will have maximum range (distance) if we aim the object at 45°. Aside: Why? Let’s let range (R) be a function of angle (θ): R = v^2/g * sin(2 * θ) Find the critical points by finding the zero of the first derivative: dR/dθ = 2 * v^2/g * cos (2 * θ) 0 = 2 * v^2/g * cos (2 * θ) 0 = cos (2 * θ) arccos 0 = 2 * θ π/2 = 2 * θ θ = π/4 Now we can use the second derivative to test whether the function is at a maximum (less than 0) and minimum (more than 0) at the crucial point. d^2 R/dθ^2 = -4 * v^2/g * sin(2 * θ) Let θ = π/4 -4 * v^2/g * sin(2 * π/4) = -4 * v^2/g * sin(π/2) = -4 * v^2/g < 0 (We are assuming the initial velocity is positive, and g ≈ 32.174 >0) Since the second derivative at θ = π/4 is negative, the range is at its maximum. Note that calculus is done when the angles are measured in radians. π/2 in degrees is 90° and π/4 in degrees is 45°. (We are only concentrating on angles between 0° and 90°) To find the maximum range and height, substitute at θ = 45° and range and height are: R = v^2 /g H = v^2 / (4 * g) The time this certain projectile lasts is: T = (v * √2) / (2 * g) Program: Keep in mind: this is done on the HP 12C (regular). For the HP 12C Platinum, the code for Last X is 43, 40 ([ g ] [ + ])

  • Page 21 of 29

    Step Code Key Notes

    01 44, 1 STO 1 Input Velocity, store in R1

    02 2 2 Calculate time of projectile

    03 10 ÷

    04 43, 36 LST x Recall 2

    05 43, 21 √x

    06 20 *

    07 3 3 g ≈ 32.174 ft/s^2 (= 9.80665 m/s^2)

    08 2 2 Earth’s gravitational constant

    09 48 .

    10 1 1

    11 7 7

    12 4 4

    13 44, 0 STO 0 Store g in R0

    14 10 ÷

    15 31 R/S Display time of projectile (s)

    16 45, 1 RCL 1 Calculate range

    17 36 ENTER

    18 20 *

    19 45, 0 RCL 0

    20 10 ÷

    21 31 R/S Display range (ft)

    22 4 4 Calculate height

    23 10 ÷

    24 43, 33, 00 GTO 00 Display height (ft)

    Input: velocity in ft/s (convert from mph to ft/s by multiplying it by 22/15) Output: time of projectile in seconds, [R/S] range of projectile in feet, [R/S] height of projectile in feet Example: V = 25 mph = 36.6666667 ft/s (110/3) Output: Time: 0.81 sec, Range: 41.79 ft, Height: 10.45 ft Source: Rosenstein, Morton. Computing With the Scientific Calculator Casio: Tokyo, Japan. 1986. ISBN-10: 1124161430

  • Page 22 of 29

    Geometric Areas: Right Triangle, Circle, Ellipse Here is a program where a choice variable (flag) is used to determine which area is to be counted. R0 = choice, R1 = see below, R2 = see below Choice 0: Triangle, R1 = A, R2 = B, area = 0.5 * A * B Choice 1: Circle, R1 = A, area = π * A^2 Choice 2: Ellipse, R1 = A, R2 = B, area = π * A * B

    Step Code Key Notes

    01 45, 0 RCL 0 Input and store the choice variable

    02 43, 35 X=0 Is choice = 0? (Triangle)

    03 43, 33, 10 GTO 10

    04 45, RCL 0 Is choice = 1? (Circle)

    05 1 1

    06 30 -

    07 43, 35 X=0

    08 43, 33, 16 GTO 16

    09 43, 33, 28 GTO 28 If not, assume choice = 2. (Ellipse)

    10 45, 1 RCL 1 Calculate area of a triangle

    11 45, 2 RCL 2

    12 20 *

    13 2 2

    14 10 ÷

    15 43, 33, 00 GTO 00

    16 45, 1 RCL 1 Calculate area of a circle

    17 2 2

    18 21 Y^X

    19 3 3 Enter approximation of π

    20 5 5

    21 5 5

    22 20 *

    23 1 1

    24 1 1

    25 3 3

    26 10 ÷

    27 43, 33, 00 GTO 00

    28 45, 1 RCL 1 Calculate area of an ellipse

    29 45, 2 RCL 2

    30 20 *

    31 3 3

    32 5 5

    33 5 5

    34 20 *

    35 1 1

    36 1 1

    37 3 3

    38 10 ÷

    39 43, 33, 00 GTO 00

  • Page 23 of 29

    Conversion from Binary to Decimal Maximum value: 1023 (1111111111 (10 ones)) R0 = binary, R1 = decimal, R2 and R3 are used

    Step Code Key Notes

    01 44, 0 STO 0 Store the binary integer, assume no sign bit

    02 43, 23 LN Determine the number of digits

    03 26 EEX

    04 1 1

    05 43, 23 LN

    06 10 ÷

    07 43, 25 INT

    08 1 1

    09 40 +

    10 44, 2 STO 2 Store number of digits in R2

    11 0 0 Initialize decimal conversion, store 0 in R1

    12 44, 1 STO 1

    13 44, 3 STO 3

    14 45, 0 RCL 0 Conversion process

    15 45, 3 RCL 3

    16 1 1

    17 40 +

    18 1 1

    19 0 0

    20 34 XY

    21 21 Y^X

    22 10 ÷

    23 43, 24 FRAC

    24 26 EEX

    25 1 1

    26 20 *

    27 43, 25 INTG

    28 2 2

    29 36 ENTER

    30 45, 3 RCL 3

    31 21 Y^X

    32 20 *

    33 44, 40, 1 STO+ 1

    34 1 1

    35 44, 40, 3 STO+ 3

    36 45, 3 RCL 3 Determine the number of digits left to work with

    37 45, 2 RCL 2

    38 30 -

    39 43, 35 X=0

    40 43, 33, 42 GTO 42

    41 43, 33, 14 GTO 14

    42 45, 1 RCL 1 Display decimal integer

    43 43, 33, 00 GTO 00

    Examples: BIN 1101, DEC 13 BIN 11000, DEC 24

  • Page 24 of 29

    Conversion from Decimal to Binary Maximum number to be converted depends on setting: 1023 (Fix 0), 511 (Fix 1), 255 (Fix 2), etc. R0 = decimal, R1 = binary, R2, R3, and R4 are used

    Step Code Key Notes

    01 44, 0 STO 0 Store decimal in R0 and R4 (temp)

    02 44, 4 STO 4

    03 43, 23 LN Determine the number of digits

    04 2 2

    05 43, 23 LN

    06 10 ÷

    07 43, 25 INTG

    08 44, 2 STO 2 Store the number of digits in R2 and R3

    09 44, 3 STO 3

    10 0 0 Initialize binary conversion, store 0 in R1

    11 44, 1 STO 1

    12 45, 4 RCL 4

    13 2 2

    14 45, 3 RCL 3 R3: digit counter

    15 21 Y^X

    16 43, 34 X≤Y

    17 43, 33, 19 GTO 19

    18 43, 33, 33 GTO 33

    19 43, 30, 4 STO- 4

    20 1 1

    21 43, 30, 3 STO- 3

    22 1 1

    23 0 0

    24 45, 3 RCL 3

    25 1 1

    26 40 +

    27 21 Y^X

    28 44, 40, 1 STO+ 1

    29 45, 3 RCL 3 Are there any more digits to work with?

    30 43, 35 X=0

    31 43, 33, 36 GTO 36

    32 43, 33, 12 GTO 12

    33 1 1

    34 44, 30, 3 STO- 3

    35 43, 33, 29 GTO 29

    36 45, 4 RCL 4

    37 44, 40, 1 STO+ 1

    38 45, 1 RCL 1 Display binary conversion

    39 43, 33, 00 GTO 00

    Example: Turn the calculator to floating mode (FIX 0) Decimal: 128, Binary: 10000000 Decimal: 463, Binary: 111001111

  • Page 25 of 29

    Coordinate locator using length (r) and pitch (% of slope) The coordinates x and y are determined using similar triangles.

    Step Code Key Notes

    01 45, 1 RCL 1

    02 1 1

    03 2 2

    04 44, 2 STO 2

    05 44, 20, 1 STO* 1

    06 45, 1 RCL 1

    07 36 ENTER

    08 20 *

    09 45, 2 RCL 2

    10 36 ENTER

    11 20 *

    12 40 +

    13 43, 21 √ √(R1^2 + R2^2)

    14 44, 3 STO 3

    15 45, 1 RCL 1 Solve the ratio R4/R1 = R3/R0

    16 45, 0 RCL 0

    17 20 *

    18 45, 3 RCL 3

    19 10 ÷

    20 44, 4 STO 4 Display y

    21 31 R/S

    22 45, 2 RCL 2 Solve the ratio R5/R2 = R3/R0

    23 45, 0 RCL 0

    24 20 *

    25 45, 3 RCL 3

    26 10 ÷

    27 44, 5 STO 5 Display x

  • Page 26 of 29

    Step Code Key Notes

    28 43,33,00 GTO 00

    Store the following values prior to running the program: R0: r R1: pitch (as a decimal amount) Pitches vs. Angles

    Angle Pitch Angle Pitch

    5° 0.08749 30° 0.57735

    10° 0.17633 45° 1.00000

    15° 0.26795 60° 1.73205

    20° 0.36397 75° 3.73205

    25° 0.46631

    14.03624° 0.25 36.86990° 0.75

    26.56505° 0.5

    Example 1: r = 17 (R0), pitch = 0.33 (R1). Result: y = 5.33 (R4), x = 16.14 (R5)

  • Page 27 of 29

    Combination/Binomial Distribution/Negative Binomial Distribution Introduction and Formulas Combination: Find the number of groups out of a possible set of objects. The order of objects obtained does not matter. Store n in R1, x in R0, and p in R2. Press [ f ] [ R↓] (CLEAR PRGM), [ R/S ] Formula: COMB(n, x) = n!/(x! * (n-x)!) Binomial Distribution: Find number of successes (x) in a fixed number of trials (n). Store n in R1, x in R0, and p in R2. Press [ g ] [ R↓ ] (GTO) 26, [R/S] Formula: COMB(n, x) * p^x * (1 – p)^(n – x) Negative Binomial Distribution: Find the number of trials (n) needed to obtain a fixed amount of successes (x). Store x in R1, n in R0, and p in R2. Press [ g ] [ R↓ ] (GTO) 43, [R/S] Formula: COMB(x – 1, n – 1) * p^(n -1) * (1 – p)^((x - 1) - (n – 1)) In the distribution calculations, p is the probability where 0 ≤ p ≤ 1. Note: R3 is used as a flag, which will allowed for branching.

    Step Code Key Notes

    Combination

    01 0 0

    02 44, 3 STO 3

    03 45, 1 RCL 1

    04 43, 3 N!

    05 45, 0 RCL 0

    06 43, 3 N!

    07 10 ÷

    08 45, 1 RCL 1

    09 45, 0 RCL 0

    10 30 -

    11 43, 3 N!

    12 10 ÷

    Flag Testing

    13 45, 3 RCL 3

    14 1 1

    15 30 -

    16 43, 35 X=0

    17 43, 33, 29 GTO 29

    18 45, 3 RCL 3

    19 2 2

    20 30 -

    21 43, 35 X=0

    22 43, 33, 49 GTO 49

    23 33 R↓

    24 33 R↓

    25 43, 33, 00 GTO 00

    Binomial Distribution

    26 1 1

  • Page 28 of 29

    Step Code Key Notes

    27 44, 3 STO 3

    28 43, 33, 03 GTO 03

    29 33 R↓

    30 45, 2 RCL 2

    31 45, 0 RCL 0

    32 21 Y^X

    33 20 *

    34 1 1

    35 45, 2 RCL 2

    36 30 -

    37 45, 1 RCL 1

    38 45, 0 RCL 0

    39 30 -

    40 21 Y^X

    41 20 *

    42 43, 33, 00 GTO 00

    Negative Binomial Distribution

    43 1 1

    44 44, 30, 1 STO- 1

    45 44, 30, 0 STO- 0

    46 2 2

    47 44, 3 STO 3

    48 43, 33, 03 GTO 03

    49 33 R↓

    50 33 R↓

    51 45, 2 RCL 2

    52 45, 0 RCL 0

    53 21 Y^X

    54 20 *

    55 1 1

    56 45, 2 RCL 2

    57 30 -

    58 45, 1 RCL 1

    59 45, 0 RCL 0

    60 30 -

    61 21 Y^X

    62 20 *

    63 43, 33, 00 GTO 00

    Examples: Find the number of combinations of groups of 2 out of possible 12 objects. 12 [STO] 1, 2 [STO] 0, [ f ] [ R↓ ] (CLEAR PRGM) Result: 66 Binomial Distribution: Toss a coin 25 times. (trails) What is the probability of tossing 10 heads? (successes) Assume a fair coin. The variables n = 25, x = 10, p = 0.5 25 [ STO ] 1, 10 [ STO ] 0, 0.5 [ STO ] 2, [ g ] [ R↓ ] (GTO) 26 [ R/S ] Result: 0.10 (0.0974166393)

  • Page 29 of 29

    Negative Binomial Distribution: Assume a fair coin. What is the probability that the 15th tossed of heads comes on the 25th toss of the coin? x = 15, n = 25, p = 0.5 25 [STO] 1, 15 [STO] 0, 0.5 [ STO ] 2, [ g ] [ R↓] (GTO) 43 [ R/S ] Result: 0.12 (0.1168999672)

    Conclusion As we can we see, we can use basic programming and mathematical techniques to expand the HP 12C beyond the financial applications. The HP 12C is one of the few RPN calculators being sold in the open market and remains a favorite. Contact Eddie Shore Email: [email protected] Blog: Eddie’s Math and Calculator Blog, edspi31415.blogspot.com

    mailto:[email protected]://www.edspi31415.blogspot.com/