Sunday, October 2, 2016

HP 12C Programming: Circles, Spheres, and Right Triangle

HP 12C Programming:  Circles, Spheres, and Right Triangle


Links to other HP 12C Programs:


HP 12C Programming Part II:  Weekday Number, Gross Up Calculation:  http://edspi31415.blogspot.com/2016/07/hp-12c-programming-part-ii-weekday.html

HP 12C Programming III: Refinancing, Advance Payments in a Lease, NPV, NFV, NUS

HP 12C:  Combination/Binomial Distribution/Negative Binomial Distribution

If you want on to calculate the date of Easter and you have the expanded HP 12C Platinum Edition:

HP 12C Platinum:  Finding the Day of Easter

Approximating π

The HP-12C does not have a π key.   We can tackle this in one of two ways:

* We can input the full approximation of π until the display no longer accepts numbers, which is up to 10 numbers.  π typed to screen capacity is 3.141592654.  Since each digit entered plus the decimal point takes a step, it will require 11 steps to enter.

* We can use the approximation π ≈ 355/113.  355/113 ≈ 3.141592920.  355/113 is an accurate approximation of π to 6 digits.  It will take a total of 8 steps to enter this approximation.   Since most of the time the HP 12C is used at Fix 2 mode (2 decimal places), this may be for most practical purposes an adequate approximation.  Just a caution:  make number of calculations low and the factors should be relatively small.

The programs represented on this blog will use the 355/113 to save space.  If you require a better approximation of π and have the space, feel free to replace 355/113 with the 3.141592654.

HP 12C:  Circles – Circumference and Area

The program calculates an approximate circumference and area of a circle given radius r.

C = 2*π*r
A = π*r^2

Here, we take 355/113 as an approximation for π.

STEP
CODE
KEY
01
44, 0
STO 0
02
3
3
03
5
5
04
5
5
05
36
ENTER
06
1
1
07
1
1
08
3
3
09
10
÷
10
44, 1
STO 1
11
20
*
12
2
2
13
20
*
14
31
R/S
15
45, 0
RCL 0
16
2
2
17
21
Y^X
18
45, 1
RCL 1
19
20
*
20
43, 33, 00
GTO 00

Registers used:
R0 = r, R1 = 335/113 ≈ π

Input:
Enter radius, r, and press [R/S].

Output:
Obtain the approximate circumference.  Press [R/S] for the area.

Examples (FIX 2):

Radius = 2.96.  Results:  Circumference ≈ 18.60, Area ≈ 27.53

Radius = 5.00    Results:  Circumference ≈ 31.42, Area ≈ 78.54

Alternate:  This uses the following shortcuts:
Number, [ENTER], [ + ] doubles the number.
Number, [ENTER], [ * ] squares the number.
That and the use of LST X reduces the number of steps to 19 and only uses one register, R0.

STEP
CODE
KEY
01
44, 0
STO 0
02
36
ENTER
03
40
+
04
3
3
05
5
5
06
5
5
07
36
ENTER
08
1
1
09
1
1
10
3
3
11
10
÷
12
20
*
13
31
R/S
14
43, 36
LST X
15
45, 0
RCL 0
16
36
ENTER
17
20
*
18
20
*
19
43, 33, 00
GTO 00



Fun fact:  A circle of radius 2 will have the same circumference and area, approximately 12.56637.                                                                                                                                                                                                                                                                                        
HP 12C:  Sphere – Surface Area and Volume

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
01
44, 0
STO 0
02
2
2
03
21
Y^X
04
4
4
05
20
*
06
3
3
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
16
3
3
17
10
÷
18
45, 0
RCL 0
19
20
*
20
43, 33, 00
GTO 00

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.       

HP 12C:  Right Triangles – Area, Hypotenuse, and Grade given Rise and Run

Let y be the rise (height) and x be the run (length) of a right triangle.  Then:

Area = 1/2 * x * y
Hypotenuse = √(x^2 + y^2)
Grade = y/x * 100%   (like slope)

STEP
CODE
KEY
01
44, 1
STO 1
02
34
X<>Y
03
44, 0
STO 0
04
20
*
05
2
2
06
10
÷
07
31
R/S
08
45, 1
RCL 1
09
2
2
10
21
Y^X
11
45, 0
RCL 0
12
2
2
13
21
Y^X
14
40
+
15
43, 21
16
31
R/S
17
45, 0
RCL 0
18
45, 1
RCL 1
19
10
÷
20
1
1
21
26
EEX
22
2
2
23
20
*
24
43, 33, 00
GTO 00

Registers Used:
R0 = rise (y), R1 = run (x)

Input:  rise [ENTER] run [R/S],  height [ENTER] length [R/S]

Output:  area of a triangle [R/S], hypotenuse [R/S], grade

Example:  rise = 430, run = 1600
Input:  430 [ENTER] 1600 [R/S]
Results:  Area: 344000, Hypotenuse: 1656.77, Grade: 26.88 (%)

I hope you find this helpful.  Can you believe it is already October?  How fast time flies,

Eddie
  
This blog is property of Edward Shore, 2016.