**Fun With the HP 71B III**

http://edspi31415.blogspot.com/2012/06/fun-with-hp-71b.html

Fun with the 71B II:

http://edspi31415.blogspot.com/2016/06/fun-with-hp-71b-ii.html

71B: Cubic Polynomials:

http://edspi31415.blogspot.com/2012/06/cubic-formula-basic-program-hp-71b.html

**3x3 Matrices: Determinant, Inverse, 3x3 Linear Systems**

EWS 6/29/2016

The program MATX3 calculates:

1. The determinant and (if possible), the inverse of a 3x3 matrix M.

2. The solution to a 3x3 linear system: Mq=D. The determinant of M will also be displayed.

If det(M) = 0, then the matrix is singular and execution stops.

The matrix M is broken into three columns (3x1 arrays): [ M ] = [ A | B | C ].

Hence M = [[ A1 B1 C1 ] [ A2 B2 C2 ] [ A3 B3 C3 ]]

Other variables used:

E = det(M)

I = M^-1. Unlike M, I will be a 3 x 3 array.

R, K, S, H: other variables used

Program MATX3 (767 bytes)

10 DESTROY A,B,I,C,R,K,S,H,D,Q

11 DISP “1. DET/INV 2. 3x3” @ WAIT 2

12 INPUT “1. D/I 2. SYS:”; H

13 DIM A(3),B(3),C(3),I(3,3),D(3)

14 OPTION BASE 1

20 FOR K=1 TO 3

21 DISP “ROW “;K @ WAIT 1

22 INPUT “A:”; A(K)

24 INPUT “B:”; B(K)

26 INPUT “C:”; C(K)

28 IF H=2 THEN INPUT “D:”; D(K)

30 NEXT K

40 DEF FND(X,Y,Z,T)=X*T-Y*Z

42 E=A(1)*FND(B(2),C(2),B(3),C(3))

44 E=E-B(1)*FND(A(2),C(2),A(3),C(3))

46 E=E+C(1)*FND(A(2),B(2),A(3),B(3))

50 DISP “DET:”; E

52 IF E=0 THEN STOP

60 I(1,1)=FND(B(2),B(3),C(2),C(3))/E

62 I(1,2)=-FND(B(1),B(3),C(1),C(3))/E

64 I(1,3)=FND(B(1),B(2),C(1),C(2))/E

66 I(2,1)=-FND(A(2),A(3),C(2),C(3))/E

68 I(2,2)=FND(A(1),A(3),C(1),C(3))/E

70 I(2,3)=-FND(A(1),A(2),C(1),C(2))/E

72 I(3,1)=FND(A(2),A(3),B(2),B(3))/E

74 I(3,2)=-FND(A(1),A(3),B(1),B(3))/E

76 I(3,3)=FND(A(1),A(2),B(1),B(2))/E

78 IF H=2 THEN 100

80 FOR R=1 TO 3

82 FOR S=1 TO 3

84 DISP “I(“; R; “,”; S; “):”; I(R,S)

86 PAUSE

88 NEXT S

90 NEXT R

92 STOP

100 DIM Q(3)

102 FOR K=1 TO 3

104 Q(K)= I(K,1)*D(1) + I(K,2)*D(2) + I(K,3)*D(3)

106 DISP “Q”; K; “:”; Q(K) @ PAUSE

108 NEXT K

10 DESTROY A,B,I,C,R,K,S,H,D,Q

11 DISP “1. DET/INV 2. 3x3” @ WAIT 2

12 INPUT “1. D/I 2. SYS:”; H

13 DIM A(3),B(3),C(3),I(3,3),D(3)

14 OPTION BASE 1

20 FOR K=1 TO 3

21 DISP “ROW “;K @ WAIT 1

22 INPUT “A:”; A(K)

24 INPUT “B:”; B(K)

26 INPUT “C:”; C(K)

28 IF H=2 THEN INPUT “D:”; D(K)

30 NEXT K

40 DEF FND(X,Y,Z,T)=X*T-Y*Z

42 E=A(1)*FND(B(2),C(2),B(3),C(3))

44 E=E-B(1)*FND(A(2),C(2),A(3),C(3))

46 E=E+C(1)*FND(A(2),B(2),A(3),B(3))

50 DISP “DET:”; E

52 IF E=0 THEN STOP

60 I(1,1)=FND(B(2),B(3),C(2),C(3))/E

62 I(1,2)=-FND(B(1),B(3),C(1),C(3))/E

64 I(1,3)=FND(B(1),B(2),C(1),C(2))/E

66 I(2,1)=-FND(A(2),A(3),C(2),C(3))/E

68 I(2,2)=FND(A(1),A(3),C(1),C(3))/E

70 I(2,3)=-FND(A(1),A(2),C(1),C(2))/E

72 I(3,1)=FND(A(2),A(3),B(2),B(3))/E

74 I(3,2)=-FND(A(1),A(3),B(1),B(3))/E

76 I(3,3)=FND(A(1),A(2),B(1),B(2))/E

78 IF H=2 THEN 100

80 FOR R=1 TO 3

82 FOR S=1 TO 3

84 DISP “I(“; R; “,”; S; “):”; I(R,S)

86 PAUSE

88 NEXT S

90 NEXT R

92 STOP

100 DIM Q(3)

102 FOR K=1 TO 3

104 Q(K)= I(K,1)*D(1) + I(K,2)*D(2) + I(K,3)*D(3)

106 DISP “Q”; K; “:”; Q(K) @ PAUSE

108 NEXT K

Example:

M = [[ 1, 2, -8 ] [ 0, -2, 9.5 ] [ 3.2, 2.7, -1 ]]

D = [[ 0.5 ] [ 1.5 ] [ 2.5 ]]

DET = -14.05

I ≈ [[ 1.6833, 1.3950, -0.2135 ] [ -2.1637, -1.7509, 0.6762 ] [ -0.4555, -0.2633, 0.1423 ]]

Solutions:

Q ≈ [[ 2.4004 ] [ -2.0178 ] [ -0.2669 ]]

M = [[ 1, 2, -8 ] [ 0, -2, 9.5 ] [ 3.2, 2.7, -1 ]]

D = [[ 0.5 ] [ 1.5 ] [ 2.5 ]]

DET = -14.05

I ≈ [[ 1.6833, 1.3950, -0.2135 ] [ -2.1637, -1.7509, 0.6762 ] [ -0.4555, -0.2633, 0.1423 ]]

Solutions:

Q ≈ [[ 2.4004 ] [ -2.0178 ] [ -0.2669 ]]

**Days From January 1, Days Between Dates**

HP 71B – Day Counts

Number of Days from January 1

D = Day

M = Month

L = Leap Year indicator (1 if the year is a leap year, 0 if it is not)

Number of Days from January 1

D = Day

M = Month

L = Leap Year indicator (1 if the year is a leap year, 0 if it is not)

Program DAYJAN1 (183 bytes)

10 DESTROY D,M,L,N

12 INPUT “MONTH:”; M

14 INPUT “DAY:”; D

16 INPUT “LEAP? (Y=1,N=0):”; L

20 IF M>2 THEN 28

21 REM M<=2

22 N=IP(30.6*(M+13))+D-429

24 GOTO 32

27 REM M>2

28 N=IP(30.6*(M+1))+D+L-64

32 DISP “# DAYS:”; N

10 DESTROY D,M,L,N

12 INPUT “MONTH:”; M

14 INPUT “DAY:”; D

16 INPUT “LEAP? (Y=1,N=0):”; L

20 IF M>2 THEN 28

21 REM M<=2

22 N=IP(30.6*(M+13))+D-429

24 GOTO 32

27 REM M>2

28 N=IP(30.6*(M+1))+D+L-64

32 DISP “# DAYS:”; N

Test 1: January 1 to May 29, non-leap year (L=0). Result: 148

Test 2: January 1 to May 29, leap year (L=1). Result: 149

**Days between Dates**

M, D, Y: Month, Day, four-digit year

Program DDAYS (299 bytes)

10 DESTROY M1, M2, D1, D2, Y1, Y2, F1, F2

11 DESTROY F,M,D,Y,N,X,Z

12 INPUT “1: M,D,Y:”; M1, D1, Y1

13 INPUT “2: M,D,Y:”; M2, D2, Y2

15 M=M1 @ D=D1 @ Y=Y1

17 GOSUB 40

19 F1=F

21 M=M2 @ D=D2 @ Y=Y2

23 GOSUB 40

25 F2=F

27 N=F2-F1

29 DISP “# DAYS:”; N

31 STOP

40 IF M>2 THEN X=IP(.4*M+2.3) ELSE X=0

42 IF M>2 THEN Z=Y ELSE Z=Y-1

44 F=365*Y+31*(M-1)+D+IP(Z/4)-X

46 RETURN

10 DESTROY M1, M2, D1, D2, Y1, Y2, F1, F2

11 DESTROY F,M,D,Y,N,X,Z

12 INPUT “1: M,D,Y:”; M1, D1, Y1

13 INPUT “2: M,D,Y:”; M2, D2, Y2

15 M=M1 @ D=D1 @ Y=Y1

17 GOSUB 40

19 F1=F

21 M=M2 @ D=D2 @ Y=Y2

23 GOSUB 40

25 F2=F

27 N=F2-F1

29 DISP “# DAYS:”; N

31 STOP

40 IF M>2 THEN X=IP(.4*M+2.3) ELSE X=0

42 IF M>2 THEN Z=Y ELSE Z=Y-1

44 F=365*Y+31*(M-1)+D+IP(Z/4)-X

46 RETURN

Test 1: January 2, 2015 to March 17, 2016 (1,2,2015 to 3,17,2016). Result: 440

Test 2: March 14, 1977 to June 29, 2016 (3,14,1977 to 6,29,2016). Result: 14352

**Great Circle Distance**

N: Longitude

E: Latitude

Separate Degrees (H), Minutes (M), and Seconds (S) during input

Program GRCIC (367 bytes)

10 DESTROY D,M,H,S

11 DESTROY N1,N2,E1,E2,G

12 DEGREES

14 DISP “N: LATITUDE” @ WAIT 1

16 DISP “E: LONGITUDE” @ WAIT 1

20 INPUT “N1: D,M,S:”; H,M,S

21 GOSUB 50

22 N1=D

25 INPUT “E1: D,M,S:”; H,M,S

26 GOSUB 50

27 E1=D

30 INPUT “N2: D,M,S:”; H,M,S

31 GOSUB 50

32 N2=D

35 INPUT “E2: D,M,S:”; H,M,S

36 GOSUB 50

37 E2=D

40 REM CALCULATION

41 G=SIN(N1)*SIN(N2)+COS(N1)*COS(N2)*COS(E1-E2)

42 G=ACOS(G)*3959*PI/180

44 DISP “DIST: “; G; “ MI”

46 STOP

50 D=SGN(H)*(ABS(H)+M/60+S/3600)

52 RETURN

10 DESTROY D,M,H,S

11 DESTROY N1,N2,E1,E2,G

12 DEGREES

14 DISP “N: LATITUDE” @ WAIT 1

16 DISP “E: LONGITUDE” @ WAIT 1

20 INPUT “N1: D,M,S:”; H,M,S

21 GOSUB 50

22 N1=D

25 INPUT “E1: D,M,S:”; H,M,S

26 GOSUB 50

27 E1=D

30 INPUT “N2: D,M,S:”; H,M,S

31 GOSUB 50

32 N2=D

35 INPUT “E2: D,M,S:”; H,M,S

36 GOSUB 50

37 E2=D

40 REM CALCULATION

41 G=SIN(N1)*SIN(N2)+COS(N1)*COS(N2)*COS(E1-E2)

42 G=ACOS(G)*3959*PI/180

44 DISP “DIST: “; G; “ MI”

46 STOP

50 D=SGN(H)*(ABS(H)+M/60+S/3600)

52 RETURN

Test:

Los Angeles, N = 34°13’0” and E = -118°15’0”

San Francisco, N = 37°47’0” and E = -112°25’0”

Distance ≈ 408.5961 mi

**Euclid Division – Finding the GCD**

Finds the GCD (greatest common divisor) between integers M
and N. The program displays a
“calculating” screen while the calculation is in process.

Program EUCLID (143 bytes)

10 DESTROY M,N,A,B,C

15 INPUT “M,N:”; M,N

20 IF M>N THEN A=M
@ B=N

22 IF M<N THEN A=N @ B=M

30 C= A – IP(A/B)*B

35 DISP C;B;A //
this is the “busy” indicator

40 IF C=0 THEN 50

45 A=B @ B=C @ GOTO 30

50 DISP “GCD:”; B

Test 1: M=144,
N=14; Result: 2

Test 2: N=14, M=144; Result: 2

**Fractions: Addition and Multiplication**

Adds or multiplies two fractions W/X and Y/Z. Gives the result in the simplest form. Proper or improper fractions only.

Separate each part with a comma (W,X,Y,Z) as prompted.

Program FRAC (380 bytes)

10 DESTROY W,X,Y,Z,N,D,H,A,B,C

20 INPUT “1. + 2. *:”,H

24 ON H GOTO 41,51

41 REM ADD

42 INPUT “W/X+Y/Z:”; W,X,Y,Z

44 N=W*Z+X*Y @ D=X*Y

46 GOSUB 61

48 DISP “=”; N; “/”; D @ STOP

51 REM MULT

52 INPUT “W/X*Y/Z:”; W

54 N=W*Y @ D=X*Z

56 GOSUB 61

58 DISP “=”; N; “/”; D @ STOP

61 REM SIMPLIFY

62 IF N>D THEN A=N @ B=D

64 IF D>N THEN A=D @ B=N

66 IF D=N THEN N=1 @ D=1 @ RETURN

68 C= A – IP(A/B)*B

69 DISP C;B;A

70 IF C=0 THEN 74

72 A=B @ B=C @ GOTO 68

74 N=N/B @ D=D/B @ RETURN

Test 1: 4/7 +
3/13; Input: 4,7,3,13.
Result: 73/91

Test 2: 4/7 * 3/13; Input: 4,7,3,13. Result:
12/91

**Statistics: Regression**

The program CURVEFIT fits data to one of five regression models:

1. Linear
Regression: y = a + bx

2. Exponential
Regression: y = a * e^(b*x)

3. Logarithm
Regression: y = a + b * ln x

4. Power
Regression: y = a * x^b

5. Inverse Regression: y = a + b/x

On the HP 71, the ln function is represented by LOG.

The program will allow different calculations with the same
data set.

Program CURVEFIT (622 bytes)

10 DESTROY H,S,D,X,Y,A,B,E

12 STAT S(2) @ CLSTAT

20 REM CHOOSE REG

22 DISP “1. LIN 2. EXP 3. LOG” @ WAIT 1.5

24 DISP “4. POW 5. INV” @ WAIT 1.5

28 INPUT “CHOICE #:”; H

29 IF E=1 THEN 60

30 REM INPUT PROCESS

32 INPUT “X,Y:”; X,Y

34 ON H GOTO 36,38,40,42,44

36 ADD X,Y @ GOTO 46

38 ADD X,LOG(Y) @ GOTO 46

40 ADD LOG(X),Y @ GOTO 46

42 ADD LOG(X),LOG(Y) @ GOTO 46

44 ADD 1/X,Y @ GOTO 46

46 INPUT “DONE? (Y=1,N=0):”; D

48 IF D=0 THEN 32

60 LR 2,1,A,B

62 IF H=2 OR H=4 THEN A=EXP(A)

64 ON H GOTO 70,72,74,76,78

70 DISP A; “+”; B; “x” @ GOTO 80

72 DISP A; “*EXP(“; B; “x)” @ GOTO 80

74 DISP A; “+”; B; “*LOG(x)” @ GOTO 80

76 DISP A; “x^”; B @ GOTO 80

78 DISP A; “+”; B; “/x” @ GOTO 80

80 PAUSE

84 DISP “ANOTHER ANALYSIS?” @ WAIT 1.5

86 INPUT “Y=1,N=0:”; E

88 IF E=1 THEN 20

90 DISP “DONE”

This blog is property of Edward Shore, 2016