HP 71B: Linear Regression, Open Channel, Sunrise/Sunset, Musical Mini-Piano
Linear Regression with a User Keyboard
This program creates a user keyboard with the following keys defined:
[ I ] Clears the statistics array and variables
[ A ] Add a data point X,Y: the sample size is shown
[ D ] Delete a data point X,Y: the sample size is shown
[ M ] Sample Mean for X and Y data. Press CONT for mean of Y values.
[ S ] Sums for X and Y data. Press CONT for sum of Y values.
[ E ] Standard Deviation for X and Y data. Press CONT for standard dev. of Y values.
[ R ] Execute Linear Regression. A = intercept, B = slope, correlation is calculated, fit to the line Y = A + B*X
[ H ] Help: cycles what all the keys do
[ X ] Clears all the user keys, prepares you to go to the next program
PROGRAM STATLIN
689 bytes, 1/26/2019
10 DEF KEY "I", 'RUN 110'
20 DEF KEY "A", 'RUN 200'
30 DEF KEY "D", 'RUN 300'
40 DEF KEY "M", 'RUN 400'
45 DEF KEY "S", 'RUN 440'
50 DEF KEY "E", 'RUN 500'
60 DEF KEY "R", 'RUN 600'
70 DEF KEY "X", 'RUN 700'
75 DEF KEY "H", 'RUN 750'
80 USER ON
90 END
110 DESTROY S,A,B,X,Y,H$,I
120 STAT S(2) @ PRINT "ALL CLEAR"
130 END
200 INPUT "+ X,Y:";X,Y
210 ADD X,Y & DISP "N=";TOTAL(0)
220 END
300 INPUT "- X,Y:";X,Y
310 DROP X,Y & DISP "N=";TOTAL(0)
320 END
400 PRINT "X-BAR=";MEAN(1) @ PAUSE
420 PRINT "Y-BAR=";MEAN(2)
430 END
440 PRINT CHR$(28);"X=";TOTAL(1) @PAUSE
450 PRINT CHR$(28);"Y=";TOTAL(2)
460 END
500 PRINT "sX:";SDEV(1) @ PAUSE
510 PRINT "sY:";SDEV(2)
520 END
600 LR 2,1,A,B
610 PRINT "INT=";A @ PAUSE
620 PRINT "SLP=";B @ PAUSE
630 PRINT "r=";CORR(2,1) @ PAUSE
640 PRINT "Y=";A;"+";B;"X"
650 END
700 PURGE KEYS @ USER OFF
710 PRINT "EXIT COMPLETE"
750 FOR I=1 TO 8
760 READ H$ @ PRINT H$ @ WAIT 1
770 DATA "I: CLEAR","A: ADD","D: DEL","M: MEAN","S: SUMS","E: SDEV","R: A+BX","X: EXIT"
780 NEXT I
790 PRINT "READY." @ END
Example to try:
Data: X,Y
-5.56, 0.79
-4.30, 0.84
1.86, 1.93
2.24, 2.01
3.95, 2.26
To add data: (in USER mode) [ A ] -5.56, 0.79 [END LINE] (repeat for all data points)
Results: n = 5
Mean:
[ M ] "X-BAR=" -0.362 [ f ] [ + ] (CONT) "Y-BAR=" 1.566
Sums:
[ S ] "∑X=" -1.81 [ f ] [ + ] (CONT) "∑Y=" 7.83
Standard Deviations:
[ E ] "sX=" 4.26696847891 [ f ] [ + ] (CONT) "sY=" 0.696512742166
Linear Regression:
[ R ] "INT=" 1.62489805306 [ f ] [ + ] (CONT)
"SLP=" 0.162701804029 [ f ] [ + ] (CONT)
"r=" 0.996741950615 [ f ] [ + ] (CONT)
"Y=1.6248905306 + 0.162701804029 X"
Open Channel Parameters
Source:
Michael R. Lindberg, PE Civil Engineering Reference Manual for the PE Exam 11th Edition Professional Publications Inc., Belmont, CA 2008 ISBN-13: 978-1-59126-129-2
The program OPENFLOW calculates the following:
Area
Wetted Perimeter
Hydraulic Radius
Hydraulic Depth
Uniform Section Factor
of conductors of four shapes: rectangle, trapezoid, triangle, and circle.
PROGRAM OPENFLOW
781 bytes, 1/25/2019
10 DESTROY K,D,B,P,R,T,H,W
20 DEGREES
30 DISP "1. RECTANGLE" @ WAIT 1
40 DISP "2. TRAPEZOID" @ WAIT 1
50 DISP "3. TRIANGLE" @ WAIT 1
60 DISP "4. CIRCLE" @ WAIT 1
70 DISP "ELSE. REPEAT" @ WAIT .5
80 INPUT "CHOICE (1-4,E):"; K
90 IF K=1 THEN 1010
100 IF K=2 THEN 2010
110 IF K=3 THEN 3010
120 IF K=4 THEN 4010
130 GOTO 30
1010 INPUT "WIDTH,DEPTH:";W,D
1020 A=D*W @ P=2*D+W @ R=A/P
1030 H=A/W @ S=A*R^(2/3)
1040 GOTO 5010
2010 INPUT "DEPTH:";D
2012 INPUT "WIDTH-LONG:";W
2014 INPUT "WIDTH-SHORT:";B
2016 INPUT "ANGLE:";T
2020 A=D*(B+D/TAN(T)) @ P=B+2*(D/SIN(T)) @ R=A/P
2030 H=A/W @ S=A*R^(2/3)
2040 GOTO 5010
3010 INPUT "WIDTH:";W
3012 INPUT "DEPTH:";D
3014 INPUT "ANGLE:";T
3020 A=D^2/TAN(T) @ P=2*D/SIN(T) @ R=A/P
3030 H=A/W @ S=A*R^(2/3)
3040 GOTO 5010
4010 INPUT "RADIUS:";R
4012 INPUT "ANGLE:";T @ T=PI*T/180
4014 RADIANS
4020 A=1/8*(T-SIN(T))*D^2 @ P=T*D/2 @ R=A/P
4030 H=A/D @ S=A*SQR(D)
4040 GOTO 5010
5010 PRINT "AREA=";A @ PAUSE
5020 PRINT "WET PERIM.=";P @ PAUSE
5030 PRINT "HYD. RADIUS=";R @ PAUSE
5040 PRINT "HYD. DEPTH=";H @ PAUSE
5050 PRINT "SECTION FACTOR=";S
5060 END
Approximate Time of Sunrise and Sunset
Source:
Hewlett Packard "HP-65 Aviation Pac" 1974
The program SUNTIME approximates the time of sunset and sunrise based on a date in a general 365-day calendar, the person's location (longitude (east is negative, west is positive) and latitude (north is positive, south is negative)), and the time zone.
Time Zone Table (United States/Mexico/Canada)
Hours from GMT:
Hawaii: Standard and Daylight: -10
Alaska: Standard: -9, Daylight: -8
Pacific: Standard: -8, Daylight: -7
Mountain: Standard: -7, Daylight: -6
Central: Standard: -6, Daylight: -5
Eastern: Standard: -5, Daylight: -4
Program SUNTIME
494 bytes, 1/24/2019
10 DESTROY T,E,D,A,Z,G,C
11 DESTROY S,S1,S2,S3
12 DESTROY O1,O2,O3,O,U1,U2,U3,U
14 DEGREES
16 INPUT "MONTH: ";M
20 INPUT "DAY: ";D
26 INPUT "LONG (E/W):D,M,S:";O1,O2,O3
27 O=O1+O2/60+O3/3600
30 INPUT "LAT (S/N):D,M,S:";U1,U2,U3
32 U=U1+U2/60+U3/3600
35 INPUT "TIME ZONE:";Z
40 T=.988*(D-1+30.3*(M-1))
45 E=.123*COS(T+87)-1/6*SIN(2*T+20)
50 C=-23.439*COS(T+10)
55 S=(O-ACOS(-TAN(C)*TAN(U)))/15-E+12+Z
57 S1=IP(S)
59 S2=IP(FP(S)*60)
61 S3=FP(FP(S)*60)*60
65 DISP "Sunrise: ";S1;":";S2;":";S3 @ PAUSE
75 N=(O+ACOS(-TAN(C)*TAN(U)))/15-E+12+Z
77 N1=IP(N)
79 N2=IP(FP(N)*60)
81 N3=FP(FP(N)*60)*60
85 DISP "Sunset: ";N1;":";N2;":";N3
Example:
Time: January 26 (Month = 1, Day = 26)
Place: Farifield, CA: 38°15′28″N 122°3′15″W
Time Zone: -8 (Standard)
Inputs:
MONTH: 1
DAY: 26
LONG: 122,3,15
LAT: 38,15,28
TIME ZONE: -8
Results:
Sunrise: 7 : 24 : 19.09497708
Sunset: 17 : 16 : 17.62419468
Musical Mini-Piano
Key map:
[ A ]: A
[ W ]: A#
[ S ]: B
[ D ]: C
[ R ]: C#
[ F ]: D
[ T ]: D#
[ G ]: E
[ H ] : F
[ U ]: F#
[ J ]: G
[ I ]: G#
[ K ]: A (higher octave)
[ O ]: One octave higher
[ L ]: One octave lower
[ P ]: Double the length of the note
[ = ]: Halve the length of the note
[ X ]: Exit, clears all the user keys
Default octave: A4 (220 HZ) to A5 (440 Hz)
Default note length: 1/4 second
Program PIANO
743 bytes, 1/27/2019
100 DESTROY A,N,P
110 A=2^(1/12) @ N=0 @ P=0
112 DEF KEY "A", 'BEEP 220.0*2^N,.25*2^P': ! A
114 DEF KEY "W", 'BEEP 233.1*2^N,.25*2^P': ! A#
116 DEF KEY "S'", 'BEEP 246.9*2^N,.25*2^P': ! B
118 DEF KEY "D", 'BEEP 261.6*2^N,.25*2^P': ! C
120 DEF KEY "R", 'BEEP 277.2*2^N,.25*2^P': ! C#
122 DEF KEY "F", 'BEEP 293.7*2^N,.25*2^P': ! D
124 DEF KEY "T", 'BEEP 311.0*2^N,.25*2^P': ! D#
126 DEF KEY "G", 'BEEP 329.6*2^N,.25*2^P': ! E
128 DEF KEY "H", 'BEEP 349.2*2^N,.25*2^P': ! F
129 DEF KEY "J", 'BEEP 392.0*2^N,.25*2^P': ! G
130 DEF KEY "U", 'BEEP 370.0*2^N,.25*2^P': ! G#
132 DEF KEY "I", 'BEEP 415.3*2^N,.25*2^P': ! F
134 DEF KEY "K", 'BEEP 440.0*2^N,.25*2^P': ! A
136 DEF KEY "O", 'N=N+1@ PRINT "OCTAVE UP" ':
138 DEF KEY "L", 'N=N-1 @ PRINT "OCTAVE DOWN" ':
140 DEF KEY "P", 'P=P+1 @ PRINT "NOTE x2" ':
142 DEF KEY "=", 'P=P-1 @ PRINT "NOTE /2" ':
144 DEF KEY "X", 'RUN 400':
146 USER ON
148 END
400 DESTROY A,N,P
410 PURGE KEYS
420 USER OFF
430 PRINT "EXIT COMPLETE"
440 END
Eddie
All original content copyright, © 2011-2019. 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.
Feel free to use this pic whenever it's Friday. Even if it's Monday. :) |
Linear Regression with a User Keyboard
This program creates a user keyboard with the following keys defined:
[ I ] Clears the statistics array and variables
[ A ] Add a data point X,Y: the sample size is shown
[ D ] Delete a data point X,Y: the sample size is shown
[ M ] Sample Mean for X and Y data. Press CONT for mean of Y values.
[ S ] Sums for X and Y data. Press CONT for sum of Y values.
[ E ] Standard Deviation for X and Y data. Press CONT for standard dev. of Y values.
[ R ] Execute Linear Regression. A = intercept, B = slope, correlation is calculated, fit to the line Y = A + B*X
[ H ] Help: cycles what all the keys do
[ X ] Clears all the user keys, prepares you to go to the next program
PROGRAM STATLIN
689 bytes, 1/26/2019
10 DEF KEY "I", 'RUN 110'
20 DEF KEY "A", 'RUN 200'
30 DEF KEY "D", 'RUN 300'
40 DEF KEY "M", 'RUN 400'
45 DEF KEY "S", 'RUN 440'
50 DEF KEY "E", 'RUN 500'
60 DEF KEY "R", 'RUN 600'
70 DEF KEY "X", 'RUN 700'
75 DEF KEY "H", 'RUN 750'
80 USER ON
90 END
110 DESTROY S,A,B,X,Y,H$,I
120 STAT S(2) @ PRINT "ALL CLEAR"
130 END
200 INPUT "+ X,Y:";X,Y
210 ADD X,Y & DISP "N=";TOTAL(0)
220 END
300 INPUT "- X,Y:";X,Y
310 DROP X,Y & DISP "N=";TOTAL(0)
320 END
400 PRINT "X-BAR=";MEAN(1) @ PAUSE
420 PRINT "Y-BAR=";MEAN(2)
430 END
440 PRINT CHR$(28);"X=";TOTAL(1) @PAUSE
450 PRINT CHR$(28);"Y=";TOTAL(2)
460 END
500 PRINT "sX:";SDEV(1) @ PAUSE
510 PRINT "sY:";SDEV(2)
520 END
600 LR 2,1,A,B
610 PRINT "INT=";A @ PAUSE
620 PRINT "SLP=";B @ PAUSE
630 PRINT "r=";CORR(2,1) @ PAUSE
640 PRINT "Y=";A;"+";B;"X"
650 END
700 PURGE KEYS @ USER OFF
710 PRINT "EXIT COMPLETE"
750 FOR I=1 TO 8
760 READ H$ @ PRINT H$ @ WAIT 1
770 DATA "I: CLEAR","A: ADD","D: DEL","M: MEAN","S: SUMS","E: SDEV","R: A+BX","X: EXIT"
780 NEXT I
790 PRINT "READY." @ END
Example to try:
Data: X,Y
-5.56, 0.79
-4.30, 0.84
1.86, 1.93
2.24, 2.01
3.95, 2.26
To add data: (in USER mode) [ A ] -5.56, 0.79 [END LINE] (repeat for all data points)
Results: n = 5
Mean:
[ M ] "X-BAR=" -0.362 [ f ] [ + ] (CONT) "Y-BAR=" 1.566
Sums:
[ S ] "∑X=" -1.81 [ f ] [ + ] (CONT) "∑Y=" 7.83
Standard Deviations:
[ E ] "sX=" 4.26696847891 [ f ] [ + ] (CONT) "sY=" 0.696512742166
Linear Regression:
[ R ] "INT=" 1.62489805306 [ f ] [ + ] (CONT)
"SLP=" 0.162701804029 [ f ] [ + ] (CONT)
"r=" 0.996741950615 [ f ] [ + ] (CONT)
"Y=1.6248905306 + 0.162701804029 X"
Open Channel Parameters
Source:
Michael R. Lindberg, PE Civil Engineering Reference Manual for the PE Exam 11th Edition Professional Publications Inc., Belmont, CA 2008 ISBN-13: 978-1-59126-129-2
The program OPENFLOW calculates the following:
Area
Wetted Perimeter
Hydraulic Radius
Hydraulic Depth
Uniform Section Factor
of conductors of four shapes: rectangle, trapezoid, triangle, and circle.
PROGRAM OPENFLOW
781 bytes, 1/25/2019
10 DESTROY K,D,B,P,R,T,H,W
20 DEGREES
30 DISP "1. RECTANGLE" @ WAIT 1
40 DISP "2. TRAPEZOID" @ WAIT 1
50 DISP "3. TRIANGLE" @ WAIT 1
60 DISP "4. CIRCLE" @ WAIT 1
70 DISP "ELSE. REPEAT" @ WAIT .5
80 INPUT "CHOICE (1-4,E):"; K
90 IF K=1 THEN 1010
100 IF K=2 THEN 2010
110 IF K=3 THEN 3010
120 IF K=4 THEN 4010
130 GOTO 30
1010 INPUT "WIDTH,DEPTH:";W,D
1020 A=D*W @ P=2*D+W @ R=A/P
1030 H=A/W @ S=A*R^(2/3)
1040 GOTO 5010
2010 INPUT "DEPTH:";D
2012 INPUT "WIDTH-LONG:";W
2014 INPUT "WIDTH-SHORT:";B
2016 INPUT "ANGLE:";T
2020 A=D*(B+D/TAN(T)) @ P=B+2*(D/SIN(T)) @ R=A/P
2030 H=A/W @ S=A*R^(2/3)
2040 GOTO 5010
3010 INPUT "WIDTH:";W
3012 INPUT "DEPTH:";D
3014 INPUT "ANGLE:";T
3020 A=D^2/TAN(T) @ P=2*D/SIN(T) @ R=A/P
3030 H=A/W @ S=A*R^(2/3)
3040 GOTO 5010
4010 INPUT "RADIUS:";R
4012 INPUT "ANGLE:";T @ T=PI*T/180
4014 RADIANS
4020 A=1/8*(T-SIN(T))*D^2 @ P=T*D/2 @ R=A/P
4030 H=A/D @ S=A*SQR(D)
4040 GOTO 5010
5010 PRINT "AREA=";A @ PAUSE
5020 PRINT "WET PERIM.=";P @ PAUSE
5030 PRINT "HYD. RADIUS=";R @ PAUSE
5040 PRINT "HYD. DEPTH=";H @ PAUSE
5050 PRINT "SECTION FACTOR=";S
5060 END
Approximate Time of Sunrise and Sunset
Source:
Hewlett Packard "HP-65 Aviation Pac" 1974
The program SUNTIME approximates the time of sunset and sunrise based on a date in a general 365-day calendar, the person's location (longitude (east is negative, west is positive) and latitude (north is positive, south is negative)), and the time zone.
Time Zone Table (United States/Mexico/Canada)
Hours from GMT:
Hawaii: Standard and Daylight: -10
Alaska: Standard: -9, Daylight: -8
Pacific: Standard: -8, Daylight: -7
Mountain: Standard: -7, Daylight: -6
Central: Standard: -6, Daylight: -5
Eastern: Standard: -5, Daylight: -4
Program SUNTIME
494 bytes, 1/24/2019
10 DESTROY T,E,D,A,Z,G,C
11 DESTROY S,S1,S2,S3
12 DESTROY O1,O2,O3,O,U1,U2,U3,U
14 DEGREES
16 INPUT "MONTH: ";M
20 INPUT "DAY: ";D
26 INPUT "LONG (E/W):D,M,S:";O1,O2,O3
27 O=O1+O2/60+O3/3600
30 INPUT "LAT (S/N):D,M,S:";U1,U2,U3
32 U=U1+U2/60+U3/3600
35 INPUT "TIME ZONE:";Z
40 T=.988*(D-1+30.3*(M-1))
45 E=.123*COS(T+87)-1/6*SIN(2*T+20)
50 C=-23.439*COS(T+10)
55 S=(O-ACOS(-TAN(C)*TAN(U)))/15-E+12+Z
57 S1=IP(S)
59 S2=IP(FP(S)*60)
61 S3=FP(FP(S)*60)*60
65 DISP "Sunrise: ";S1;":";S2;":";S3 @ PAUSE
75 N=(O+ACOS(-TAN(C)*TAN(U)))/15-E+12+Z
77 N1=IP(N)
79 N2=IP(FP(N)*60)
81 N3=FP(FP(N)*60)*60
85 DISP "Sunset: ";N1;":";N2;":";N3
Example:
Time: January 26 (Month = 1, Day = 26)
Place: Farifield, CA: 38°15′28″N 122°3′15″W
Time Zone: -8 (Standard)
Inputs:
MONTH: 1
DAY: 26
LONG: 122,3,15
LAT: 38,15,28
TIME ZONE: -8
Results:
Sunrise: 7 : 24 : 19.09497708
Sunset: 17 : 16 : 17.62419468
Musical Mini-Piano
Key map:
[ A ]: A
[ W ]: A#
[ S ]: B
[ D ]: C
[ R ]: C#
[ F ]: D
[ T ]: D#
[ G ]: E
[ H ] : F
[ U ]: F#
[ J ]: G
[ I ]: G#
[ K ]: A (higher octave)
[ O ]: One octave higher
[ L ]: One octave lower
[ P ]: Double the length of the note
[ = ]: Halve the length of the note
[ X ]: Exit, clears all the user keys
Default octave: A4 (220 HZ) to A5 (440 Hz)
Default note length: 1/4 second
Program PIANO
743 bytes, 1/27/2019
100 DESTROY A,N,P
110 A=2^(1/12) @ N=0 @ P=0
112 DEF KEY "A", 'BEEP 220.0*2^N,.25*2^P': ! A
114 DEF KEY "W", 'BEEP 233.1*2^N,.25*2^P': ! A#
116 DEF KEY "S'", 'BEEP 246.9*2^N,.25*2^P': ! B
118 DEF KEY "D", 'BEEP 261.6*2^N,.25*2^P': ! C
120 DEF KEY "R", 'BEEP 277.2*2^N,.25*2^P': ! C#
122 DEF KEY "F", 'BEEP 293.7*2^N,.25*2^P': ! D
124 DEF KEY "T", 'BEEP 311.0*2^N,.25*2^P': ! D#
126 DEF KEY "G", 'BEEP 329.6*2^N,.25*2^P': ! E
128 DEF KEY "H", 'BEEP 349.2*2^N,.25*2^P': ! F
129 DEF KEY "J", 'BEEP 392.0*2^N,.25*2^P': ! G
130 DEF KEY "U", 'BEEP 370.0*2^N,.25*2^P': ! G#
132 DEF KEY "I", 'BEEP 415.3*2^N,.25*2^P': ! F
134 DEF KEY "K", 'BEEP 440.0*2^N,.25*2^P': ! A
136 DEF KEY "O", 'N=N+1@ PRINT "OCTAVE UP" ':
138 DEF KEY "L", 'N=N-1 @ PRINT "OCTAVE DOWN" ':
140 DEF KEY "P", 'P=P+1 @ PRINT "NOTE x2" ':
142 DEF KEY "=", 'P=P-1 @ PRINT "NOTE /2" ':
144 DEF KEY "X", 'RUN 400':
146 USER ON
148 END
400 DESTROY A,N,P
410 PURGE KEYS
420 USER OFF
430 PRINT "EXIT COMPLETE"
440 END
Eddie
All original content copyright, © 2011-2019. 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.