You are on page 1of 41

# INTRODUCTION

The programs were chosen to provide useful calculations for many of the common problems
encountered.
They will provide you with immediate capabilities in your everyday calculations and you will
find them useful as guides to programming techniques for writing your own customized software.
The comments on each program listing describe the approach used to reach the solution and
You will find general information on how to key in and run programs under "A Word about Program
We hope that this Solutions book will be a valuable tool in your work and would appreciate your
The program material contained herein is supplied without representation or warranty of any kind.
Hewlett-Packard Company therefore assumes no responsibility and shall have no liability,
consequential or otherwise, of any kind arising from the use of this program material or any part
thereof.
e-
,j
Ii
1. ARITHMETIC
J
GEOMETRIC
J
HARMONIC
J
AND GENERALIZED MEANS • •
This program calculates the arithmetic, geometric, harmonic, and
generalized means given a set of numbers.
2. BASIC STATISTICS (TWO VARIABLES) •••••••.•••••
• • • •
• I • •
This program calculates the means, standard deviations, covariance, and
correlation coefficient given a set of number pairs.
1
4
3. ANALYSIS OF VARIANCE (ONE WAY) • • • • • • • • • • • • • • • • .• 7
This program performs a one way analysis of variance (ANOVA) for k
treatment groups containing an equal or unequal number of observations.
4. CHI-SQUARE DISTRIBUTION
• • • • •
. . . . . . . . . . . . . . . . 11
This program evaluates the chi-square density function and the cumulative
distribution for given values of x with v degrees of freedom.
5. t-DISTRIBUTION • • • • • • • • • • • • • • • • • . • • • • • • • • 14
This program evaluates the integral of the t-distribution with v degrees
of freedom for given values of x.
6. F-DISTRIBUTION ••••••••••••••••••••••• " • • 17
This program evaluates the integral of the F-distribution with degrees of
freedom VI, V2 for given values of x.
7. POISSON DISTRIBUTION • • • • • • • • • • • • • • • • . • • • • • • 20
This program evaluates the Poisson density function and cumulative distri-
bution for given values of x (positive integers) with mean = variance = A.
8. PARABOLIC CURVE FIT • • • • • • • • • • • • • • • • • • I • • • •
This program fits a parabola to a set of number pairs such that the sum of
the squares of the errors is minimized.
23
9. PAIRED t-STATISTIC • • • • . • • • . • • • • • • • • • • • • • • • 26
This program calculates the test statistic, t, and the number of degrees
of freedom given a set of paired observations from two normal populations
with unknown means.
10. t-STATISTIC FOR TWO MEANS
• • I I • • • • • • • I • • • • I • I •
This program calculates the test statistic, t, and the number of degrees
of freedom given two independent sets of observations from two normal
populations having unknown means and the same unknown variance, and given
HO:lJI - lJ2 = D.
11. CHI-SQUARE EVALUATION
• I • I • • • • • I I • • • • • • • • I • I
This program calculates x
2
given a set of paired observed and expected
frequencies or if the expected values are equal, just the set of observed
frequencies.
12. 2 X K CONTINGENCY TABLE • • • • • · • · • • • • • • • • • • •
This program calculates X
2
, the number of degrees of freedom, and
Pearson's coefficient of contingency given a 2 x k contingency table.
I •
29
32
35
HARMONIC
AND GENERALIZED MEANS
Arithmeti c mean
A= al +
n
Geometric mean
Harmonic mean
H=
Generalized mean
+ a
n
n
NOTES: 1. ak>O, k= 1, 2, •.. , n
2. M(l )=A
M (-l)=H
EXAMPLES:
Find A, G, H & M (1) for the set of
numbers
{2, 3.4, 3.41, 7, 11, 23}
SOLUTION:
GSBl
1.88 ST09
2.88 (;SB2
3.48 GSB2
3.41 GSB2
7.88 GSB2
11.88 GSB2
23.88 GSB2
GSB3
8.38
*u
R/S
4.48 .U
R/S
5.87
u*
R.·'S
8.38 ft.
1
A
H
G
M(t)
2
User Instructions
INSTRUCTIONS
INPUT
KEYS
OUTPUT
STEP
DATA/UNITS DATA/UNITS
1 Key in the program
I 10
2 Initialize

1.00
3 If M(t) is desired t
§QJCO
t
4 Perform step 4 for k = 1, 2, ... n
a
k

2
I
a
k
5 Compute A
IGSB
II
3
I
A
6 Compute H
[BLUO
H
7 Compute G
I R/S
ILJ
G
8 Compute M(t)
I R/S
II I
M(t)

00
I II I
00
01 I
01 I
I
00
01 I
00
01 I
00
1 II I
00

_. 1 II I
00

--
LJO
--
1-------- 1----
I
1 11 1
,I
ProgralD Listings
3
el
82 [LPG initial ize
eJ
84 STfJ2
es R.·'S
136
87 STx2
88 1/?
139 LSr?
18 1+
11
, C:T¥
12 LSTX
13 PCL9
14
}Ix
1S ST+S
16 PJ·
17
p ... s
18 tLBLJ
19 x
28 P···S ***A
21 IN
....
1/,\'

2?
R.· .. S ***H
24 RCL2
25 PC.S
26 1
···V . i,
27

28
p ..s
***G
29 RCL8
38 pC.e

"'1"
PCL9 .. fL.
7"'1
l ..···X .. '",,'
34
\/X
35 p·· .. S
***M(t)
***"Printx" may replace "R/S" ,
REGISTERS
0 2
'ITa
3 4 5
6 7 8
La t
9
t
.0 .1

n La
.2 .3
l/a
.4 .5 16 17
L
18 19 20 21 22 23
24 25 26 27 28 29
JI
,
4
BASIC STATISTICS (TWO VARIABLES)
This program calculates means, standard
deviations, covariance and correlation
coefficient derived from a set of data
points
{(x., y.), i=l, 2, ... , n}
, ,
means
standard deviations
=j
l: x.
2
- nXL
s = ,
x ----
n - 1
_ 1 n
y = - L y.
n . 1 '
,=
(or ax = -,=---- x n

- nx
2
= sJn-l )
n
s =
y
n -
(or a =jl:Y. 2 - ny2
y = ,

covariance
s jn-l )
y n
s xy = n 1 (l: xi Y i - l: x il: Y i )
(or s 1 [l: x.y. - 1 l: X.l: Y J )
xy n ',n , ,
correlation coefficient

rXY= s s
x y axay
NOTE: n is a positive integer and
n> 1.
EXAMPLE:
x. 26 30 44 50 62 68 74
,
y. 92 85 78 81 54 51 40
,
SOLUTION:
I;SBl
92.88 ENH
26.88 I+
85.68 EUH
J8.e8 I+
78.813 ENTt
44.88 I+
81.88 ENTt
58.88 1+
54.88 EflTt
62.88 I+
51.813 ENTt
68.88 I+
48.88 ENTt
74.88 I+
p. ..···S
58.57
***
P'/S
68.71
***
R/S
18.58 ttl.
R/S
28.ee t.u
•.,C'
0" "_,
-354.14
***
I( ..··S
-8.96 HI
I;S82
f., 1"l'
.i.l .... ",'
.. , .....
P."'-S
18.51 HI/.'
R.· ..S
.:!f:J#:
R.· ..·S
-8.96
.. **
x
Y
sx
s
y
s
xy
r
xy
a
X
a
y
Sxy
r
xy
--
- !
5
User Instruetions
INPUT
KEYS
OUTPUT
STEP INSTRUCTIONS
DATA/UNITS DATA/UNITS
l. Key in the program
I 10
2. Initialize

3. Perform steps 3-4 for i-l,2, ... n
Yi I ENTtIO
4.
xi
1
(correct erroneous data)
Yk I ENTt II
1
xk
wCU
5. Calculate means:
I R/S
II I
-
x
I P.LS II
I y
6a.
Calculate sample standard deviations: [MJO S
I R/S II I
Sv
7a.
Calculate sample covarience
I RLS 10
S "
'J
8a.
Calculate correlation coefficient
I RLS 10
rV\l
AND OR:
GiJ[LJ
'J
6b.
Calculate populations standard deviations: cry
I
crv
7b.
Calculate population covarience

Sxy
8b.
Calculate correlation coefficient

rxy
00
I
00
I II 1

--- - - ----
-- ------
f------ f----- ----- --------- --------- 1---------

f---------
----- 1---------- ----------- ----- ---------- ------ -- ------ 1---------
----
r---l r---l
I
6
81 tLBLl
Initialize
82 CL!
83 R.·'S
84 RC.e
8S
f
..
86
- n-l
87 ST!)l
88 RC.13
89
18 [1:
11 ST02
12 x
13 R,'S
***
-
x
14
\;· .. v
11..-'
IS R.·'S
*** Y
16 S
17
R ...··S
***
Sx
18 x:v
19 R.·'S ***
Sy
213
. ~ .
21 tLBL8
22 RC.5
23 RC.!
24 RC.J
25
x
26 RC.8
27
28 -
29 RCU
n-l or n
38
::'1 R..rS ***
Sxy
or
Sxy
I
32 Xty SxSy
or oxoy
JJ
34 R.··"S
**
rxy
3S tLBL2
36 S
J7 RCL2
38
x
** "Printx" may b inserted before "R S".
39 R.·'S
***ox
*** "Printx" may b ~ inserted
48
y ..... '
before or in p ace of "RIS".
II+-.
41 RCL2
42 x
43 R.·'S ***0
Y
44
.. \
4S RC.e
46 STOI
°xOy
4" N .1
48 GTOB
0 1
n-l
2
~ REGISTERS
-n- 3 4 5
6 7 8 9 .0
n
.1
l:x
.2
l:x
2
.3
l:y
.4 l:y2 .5
l:xy
16 17
18 19 20 21 22 23
24 25 26 27 28 29
7
ANALYSIS OF VARIANCE (ONE WAY)
The one-way analysis of variance tests
the differences between the population
means of k treatment groups. Group i
(i= 1, 2, ... , k) has n
i
observations
(treatment group may have equal or un-
equal number of observations).
sum
i
= sum of observations in treat-
ment group i
n.
1
L: x.·
j=l 1J
Total SS=
Treat SS=
k n
i
L: L:
i =1 j=l
k
X .• 2 -
1J
X •• ) 2
1J
L: n.
1
i=l
n.
1
k
(L: x .. ) 2
j=l
1J
L:
n.
i=l 1
k
n.
1
(L:
L:
x .. ) 2
i=l j=l
1J
k
L:
n.
i=l
1
Error SS = Total SS - Treat SS
df
1
= Treat df = k-l
k
df 2 = Error df = L: n
i
- k
i=l
Treat SS
Treat MS = Treat df
Error MS =
Error SS
Error df
F = Treat MS (with k - 1 and
Error MS
k
L: n. - k degrees of freedom)
. 1 1
1=
Total SS, Treat SS, Error SS are in
registers R
1
, R
2
, R
3

REFERENCE: Mathematical Statistics,
J.E. Freund, Prentice Hall, 1962
EXAMPLE:
j
23456
10 8 5 12 14 11
Treatment 2 698 13
3 14 13 10 17 16
,
8
SOLUTION:
~ -
L P ~
18.88 1+
8.88 1+
5.88 1+
12.88 1+
14.88 1+
11.88 1+
t;SBl
68.88
***
Suml
6.88 !+
9.88 1+
8.88 1+
13.88 1+
I;S81
36.88
***
Sum2
14.88 1+
13.88 1+
18.88 1+
17.88 1+
16.88 1+
t;S81
78.88 Ut Sum3
P/S
2.88
***
dfl
p/S
~
12.88
t**
df2
Po'S
7 "Q
",'. i ...
t**
F
User Instruetions
9
INSTRUCTIONS
INPUT
KEYS
OUTPUT
STEP
DATA/UNITS DATA/UNITS
1 Key in the program
00
2 Initialize
[ I J ~
3 Perform 3-5 for i= 1, 2, ••• k
00
4 Perform 4 for j= 1, 2, ... n;
X;;
~ O
j
'v
(correct erroneous data, Xim
X;m
I
f
II E-
I
5 Calculate Sum
~ ~
Sum;
6 Calculate Treat df
IRIS
10
df,
7 Calculate Error df
IRIS II I
df?
8 Calculate F
LBLLJO
F
9 (optional) Total SS IRCL II 1
I
Total SS
10 (optional) Treat SS WG] Treat SS
11 (optional) Error SS wCL] Error SS
12 For a new case, go to step 2
00
I II I
00
01 I
00
01 I
00
00
00
I II I
00
C ~ O
00
L ~ L ~
1 11 1
10
ProgralD Listings
81 ,Leu
82 1
83 ST+4
84 RC.l
85 ST+?
86 Xt
87 PC.8
88 STfS
89
18 ST+3
11 8
~ restore
12 ST.8
registers
13 RC.1
14 5-.1
15 R./S **5um.
1
16 ,LBL2
17 RC.2
18 RCL7
19 x
t
28 PCL5
21
22 -
23 ST01
Total 55
24 PCLJ
25 LSTX
26 -
?7
ST02 Treat 55 ... !
28 -
29 STD3
Error 55
38 LSTX
31 RCL4
32 1
33 -
34 R/S
***df
1
35
36 XtV
37 PCLS
38 PCL4
39 -
48 P/S ***df
2
41
42
** IIPrintx
ll
be inserted before IIRI
43 P·'S ***F
may
II
iIr**IPrintx" may be inserted before or
in place of "RI
II
.
REGISTERS
~
n.
L:
0 1
Total 55
2
Treat 55
3
Error 55
4
k
5
;=1
1
6
7k
n. 8 9 .0
n
.1 n.
1 1
. 2
k
n.
L: L:
X .•
.4 .5 16
L:
X ••
1
;=1 j=l
lJ
j=l
lJ
L: L:
X .•
2 20 21 22
i=l j=l
lJ
25 26 27 28 29

11
CHI-SQUARE DISTRIBUTION
This program evaluates the chi-square
density
v X
-1 -"2""
f(x)= --- X
2
e
v
i2r
where x 0
v is the degrees of freedom.
fIx)
o
x
Series approximation is used to evaluate
the cumulative distribution
P(x)= fX f(t) dt
o
... 1+ f xk
k-l
t
-
- (V+2l(V+4l ... (V+2klJ
The program computes successive partial
sums of the above series. When two
consecutive partial sums are equal, the
value is used as the sum of the series.
If v is even,
If v is odd,
r = -2) ...
1
r ("2) = ;;
REFERENCE: Handbook of Mathematical
Functions. Abramowitz and Stegun,
National Bureau of Standards, 1968
NOTES: 1. Program requires
2. If both x and v are large,
f(x) may overflow the machine.
EXAMPLES:
1. v= 20,
x= 9.591;
x= 15.
SOLUTION:
28.80 ENH
9.591 GS81
8.82 *** f(x)
R.·'S
8.83 *** P(x)
15.88 ST02
GS82
8.86 *** f(x)
p..·'·s
13.22 u* P(x)
I'
12
EXAMPLE:
2. v= 3,
x= 7.82.
SOLUTION:
J. 00
7.82 fSBl
8. 02 *11:* f (x )
R.···S
8.95 lH' p(x)
User Instructions
STEP INSTRUCTIONS
INPUT
KEYS
DATA/UNITS
1 Key in the program
DD
2 Enter degrees of freedom
v
IENTt I D
3 Enter x
x
DD
4 Compute f(x)

5 Compute P(x)
IRIS
II I
6 For a different x:
x

7 Calculate f(x) and go to step 5
IGSB
ILLJ
8 For a new case, go to step 2
I II I
DD
I II I
DD
DD
DD
I
DD
DD
DD

DD
LJI I
L __ I--

OUTPUT
DATA/UNITS
f(x)
P(x)
f(x)
<---------
13
81 48
82 ST02 x 49 CHS
B3 PJ· 58
eY.
84 1
r,
,.; 1 x
135 STOJ 52 2
86
Voot",.'
ii<fa;
v
53 PCL!
87 2
54
yx
88
c;e:
,. ... '
89 ST01 56 RCL!
18 INT
57
11
I
i...._. I II 58 ST05
12 X1Y?
v even or odd? 59 P/S ***f(x)
13 Grae odd 68 PCL2
14 1
61 RCL!
15 X=1'?
f= 1 62
1
.1:> bT02
6J STx5
17 - 64 2
18 STOJ
65 RCL!
19 tLBL5
factorial loop
66
x
28 1
67 STa6
21 \'=Y? 68 1
22 GT02
69 STa4
23 -
78 tLBL8
24 STx3 71 RCL2
25 bros 72 PCLG

26 ,LBLe 73 2
?7
74 +
'-I
28 5
75 STaG
?Q
X=Y?

'-_. It
38 bT09
77 RCL4
31
X: \1 78
.x:
32 1
7Q
1 _.
STa4
., ...
-
88 + add to 1 first time
34 STn
81 xn?
.,e:
r;Toe
82 nOB
loop
36 *LBL9
83 RCL5
37 Pi
84 x
38 r'"
85 p.·'·s ***P(x)
-.., ...,
39 STx?
413 tLBL2
41 PCL2
42 PCL!
***"Printx" may rep ace "R/S".
4J 1
44 -
45
yx
46 PCL2
47 2
REGISTERS
0 1
v/2
2
x
3
1 , f (v/2)
4
used
5
used
6
used
7 8 9 .0 .1
.2 .3 .4 .5 16 17
18 19 20 21 22 23
24 25 26 27 28 29
,
14
t-DISTRIBUTION
This program evaluates the integral
for t distribution
v+l
x - -2-
I(x,v) = v dy
-x v
rn r(2")
where x>O.
v is the degrees of freedom.
EQUATIONS:
(1) v even
()
{l
1 2 1·3 IJ
1 x,v =sinS cos S+2.4 cos e+ ...
+ 1·3·5 ... (v-3) v-
2
.l
2.4.6 ... (v_2)cOS SJ
(2) v odd
- 1 v=
7f
{
2S of 1
I(x,v)= 2
2: + TI coss{sine[l ...
+ 2·4 ... (v-3) COSV-
3
S]}if v>l
1·3 ... (v-2)
-1 ( X )
where e = tan Tv
REFERENCE: Handbook of Mathematical
Functions, Abramowitz and
Stegun, National Bureau
of Standards, 1968.
EXAMPLE:
1(2.201,11)
1(2.75,30)
SOLUTIONS:
2.281 EHTt
11. 88 (;581
8.95 Ut 1(2.201,11)
2.75 EHH
38.88 t;S81
8.99 t.H: 1(2.75,30)
15
User Instructions
INPUT
KEYS
OUTPUT
STEP INSTRUCTIONS
DATA/UNITS DATA/UNITS
l. Key in the program
01 I
2. Enter x x
IENTtlO
3. Enter degrees of freedom v
00
4. Calculate I(x,v)
~ I T J
I(x,v)
I II I
00
I II I
I II I
i
!I
00·
I II I
00
01 I
00
I II I
00
01 I
00
I II I
00
01 I
00
I II I
00
00
00
L ~ I I
I II I
,
16
81 fLBU 48
82 S1O!
49 ST+6
83 RAP
58 DSZ
84 IX
51 (;107
8S
52 RCL6
86 TAH-I S3 RCL4
87 5102 e 54
x
88 RCLl 55 RTH
89 2
56 fLBL8
18
57 RCL2
11 IHT
58
...
~
12 LSTX
59
x
13 xn?
v even or odd? 68 Pi
14 (;T08
odd 61
15 8
62 STO?
2e/rr
16 STOS
63 RCLl
17 (;SB9
64 1
18 R/S
'**
I(x,v)
65 STOS
19 fLBL9
66 ST-l
28 RCL2
67 x=y"
1? v =
21 COS
68 (;T06
22 x'Z
69 GSB9
2J ST03
cos
2
e
78 RCL2
24 RCL2
71 COS
25 SIH
72 x
26 ST04
sine
TJ 2
27 RCLl
74 x
28 2
75 Pi
29 x=y?
v=2?
76
38 GTOB
?7 RCL?
31
78 +
32 1
7Q
R/S
I(x,v)
1_'
**
33 -
88 fLBL8
34 STfJ8
i=INT
(I -
1)
81 RCL4
35 1
82 R/S
**
I(x,v)
36 ST06
83 *LBL6
3? fLBL?
84 RCL?
38 RCL3'
8S R/S
**
I(x,v)
39
x
48 RCL5
41 1
42 +
43 x
44 LST>? Rs + 1
**
"Printx" may
before"
45 1
pe inserted
/S".
46 +
47 STaS
REGISTERS
0
i 1 V or v-l
2
e
3
cos
2
e
4
sine
5
Used
6
Used
7
2e/rr
8 9 ,0 .1
.2 .3 .4 .5 16 17
18 19 20 21 22 23
24 25 26 27 28 29
F DISTRIBUTION
This program evaluates the integral of
the F distribution
for given values of x(>O), degrees of
freedom vI'v
2
, provided either vI or v2
is even.
The integral is evaluated by means of
the following series:
( 1 ) v I even
(2) V2 even
Q(x)= 1- (l-t)?- ~ + v ~ t+
VI(vI+2) ... (v2+vl-4)
+ ~ ~ - - ~ ~ ~ ~ ~
2'4 ... (V2-2)
where t=
v2
EXAMPLE:
1. vI=7, v2=6, x=4.21
SOLUTION:
EXAMPLE:
4.21 fliTt
7.88 fNTt
6.88 I;SBl
8.85 u* Q(4.21)
2. vI=4, v2=20, x=2.25
SOLUTION:
2.25 fNTt
4.88 fliTt
28.88 ~ S B l
8.1e *** Q(2.25)
17
~
t 2 J
18
STEP
1
2
3
4
5
User Instructions
INPUT
KEYS INSTRUCTIONS
DATA/UNITS
Key in the program
00
Enter x
x
IENIt 10
Enter vI
VI
IENIt 10
Enter v2
v2
01 1
Calculate Q (x)
1 GSB
1
1
1
1 0
1 1 1
1 1 I
00
1 /I 1
00
01 1
00
I II I
00
01 1
00
O L ~
00
1 /I I
00
1 /I I
C ~ O
00
C ~ O
L ~ I 1
I
"
I
OUTPUT
DATA/UNITS
Q(x)
i
I
I
,
19
81 tLBL1
48 ,LBL7
82 ENTt
49 2
83 RJ.
58 ST+2
84 5T02 v2
51 ST+7
85 RJ.
52 RJ.
86 5T01 VI
53 RCL2
87
x
54 RCL7
88 +
S5
-
89
56 RCL3
18 ST03 t
57
.l(
11 RCLt
58 x
12 2
59 ST+5
13
68 DSZ
14 FRC
61 GTD7
15 Xl8'? vI even or odd?
62 ,lBL6
16 bTD9
VI odd
63 RCl5
17 bSB8 VI even
64 RCL4
18 R/S **Q(x)
65 x
19 ,lBL8
66 RTH
28 RCLJ
67 tlBL9 V2
even
21 RCl2
68 RCL1
22 2
69 RCL2
23 5T07
78 ST01
24
-
71 Xty
25
yx 72 STD2
26 ST04
73 1
27 PCL1
74 RCn
28
.,
75 - 1-t
'-
29 -
76 ST03
38 2
77 GSB8
31
78 1
32 ST08
- vx-2
79 XtY
1= --
33 X=8'?
2
88 -
34 (;TOB
81
R ..· ..S
**Q(x)
35 1
82 ,lElS
36 ST05
83 RCL4
37 RCL3
84 R/S **Q(x)
3S -
39 5T03 1-t (or t)
48 RCL2
41 2
42
43
x
**"Printx" may be inserted before "R/
"
44 ST+5
45 DSZ
46 GTO?
47 bro6
REGISTERS
t?-
0
i
1
V, or V?
2
V2 or VI
3
t, 1-t
4 or 5
used
6 7
used
8 9
(l-t)?-
.1
.2 .3 .4 .5 16 17
18 19 20 21 22 23
24 25 26 27 28 29
r
I
20
POISSON DISTRIBUTION
This program evaluates f(x) and P(x)
for a given A using the recursive
relation
A
f(x+ 1) = ---::-- f(x)
x+l
Density function
f(x) =
Cumulative distribution
x
P(x)= L: f(k)
k=O
where
mean = variance = A
A is positive
and
x is a positive integer
EXAMPLE:
A = 3.2, x = 7
SOLUTION:
3.28 I;S81
7.88 R.··'S
8.83 *** f(7)
R/S
8.98 u·t. P(7)
User Instructions
21
INPUT
KEYS
OUTPUT
STEP INSTRUCTIONS
DATA/UNITS DATA/UNITS
1 Key in the program
DD

t(U)=PlU)=
2 Enter A
A .04
f---------'-----
3 Enter x x
DD
4 Calculate f{x)

f{x)
5 Calculate P{x)
I R/S
II I
P{x)
6 For a new x, go to step 3
DD
I ID
I II
I
DD
I II I
DD
I ID
DD
I
DD

DD

DD
I II I

-------
------
--

----------
---------------
[---]
---- ------
I--
------ ------------ --- -------- ------- ------
1------ f------------------ ----------- -- ----- -- ------- --------
[--] [--]
----- ----- ----- - - - -- ---
1----] r----]
r
81 tLBLt
82 STOI A
83 CHS
84
eX
8S ST02
86
f(O)
87 STOS
x
88 8
89 STa8
18 RCL2
11 ST03
12 ST04
13 tLBLI3
14 RCLt
15 ISZ
16 RCL8
17 -
18 RCL3
19
x
28 5T03
21 ST+4
22 RCL8
23 ReLS
24 '!.n'?
25 GT08
26 RCL:?
27 R/S ***f(x)
28 1
29 RCL4
38
31

32
R/S ***P(x)
***"Printx" may be inserted before or
in place of "Ri S".
REGISTERS
0
i
1
A
2
f(O)
3
f(x)
4
P(x)
5
X
6 7 8 9 .0 .1
.2 .3 .4 .5 16 17
18 19 20 21 22 23
24 25 26 27 28 29
J
I
PARABOLIC CURVE FIT
For a set of data points {(xi'Yi)' i =
1,2, •.. ,n! this program fits a parabola
Y = azx
z
+ al x + ao
with the sum of the squares of the
errors minimized.
EQUATIONS: The normal equations are
~ x z Y = z ~ x 4 + alEx
3
+ aoExz
Exy = azEx
3
+ alEx
z
+ aoEx
Ey = azEx
z
+ alEx + aon,
where the summations are from 1 to n.
NOTE: If Ex
3
= 0, an error will occur.
-- Replace it with 10-
49

REFERENCE: "Applications Programs,
Volume 1, II Adams, Ed. Int 11.
Software Clearinghouse,
pp. 15-18.
EXAMPLE:
Xi I 0
1 1.5 3 5
-5 -24.5 -80 2
Ex.
3
= 156.38,
EXiYi
= -479.00,
,
EX.Zy.
, ,
= -2229.75
EX.4
,
= 712.06, n = 5.00, EX/ = 37.25
Ex.
,
= 10.50, EYi = -105.40
SOLUTION:
23
CLRG
2.18 EHTt
8.88 GS81
28.88 EHTt
1.88 GS81
28.88 EHTt Correct erroneous
1.88 (;584 da ta
2.88 EHTt
1.88 GS81
-5.88 EHTt
1.58 (;S81
-24.58 EHTt
3.B8 GSBI
-88.88 EHTt
5.88 GSBI
GSB2
-3.66
*u
R/S
1.85
***
IUS
a2
al
2.28 u* ao
4.88 GSB3
A
-48.83 UI Y
,I
I
24
User Instructions
INPUT
KEYS
OUTPUT
STEP INSTRUCTIONS
, DATA/UNITS DATA/UNITS
l. Key in the program
DI 1
2. Initialize

3. Perfol'm 3-4 for i = 1,2, ... n
y;
IENTt ID
4.
xi

i
(correct erroneous data
YL IENTt II
I
xk
i
5. Calculate regression coefficients:
I GSB I LLJ a2
I RLS "
I al
CB&JD
an
6.
A
I GSB "
I
A
Calculate estimated value, Y x 3 v
7.
For a new x, go to step 8
DD
DD
DD
I
DD
DD
DD

DD
I
"
I
DD
I II I
DD
I-
DD
1---

1------- -- I
I
"
I
ProgralD Listings
25
fLBU
58 RCL8
81
x Y
51 ST-7
82 1+
52 RC.5
83 LSTX
53 ST-9
84 LSTX
54 fLBU
85 3
X3
55 RCL?
86
yx
56 SH9
87 ST+8
57 RCL9
88 x
58 RCL8
89 ST+7
X4
59 x
18 IX
68 S-.5
If
. "
x
61 RCL9
12 5T+9 x2y
~ ..
t>.!: R/S
*** a2
13 RC.8 n
63 RCL6
14 R/S 64 x
15 fLBL2
Solve 3 simultan-
65 S-.3
16 RCL8
eous equations
66 RC.5
17 RC.2
67 R/S
*** al
18 ST06
68 RC.1
19 ST-:-7
69 x
78 S-.3
28 SH9
71 RC.3
21
72 R/S
*** ao
22 RC.1
73 fLBL3
23 5-:-.2
74 EHTt
x
24 ST.;8
75 X2
25 5.;.5
76 RCL9
26 RC.B
77 x
27
c· •
78
)i"V """:" • .L __ .....
• pi
28 ST.;6
7(/
1_· RC.5
29 S';.3
88 x
38 IU-
81 +
31 Ri 82 RC.3
'32 RC.1 83 +
'"
JJ S-.2 84 R/S
Y manual "Printx" op tional
34 - 85 fLBL4
Correction routine
7 ~
- 86 !- •• ! .. r
36 RCL6 87 LSTX
-':7
~ I ST-7 88 LSTX
38 ST-8
89 3
39 RC.3
98
yx
48 ST-9
91 ST-8
41 S-.5
92
x
42 RC.2
93 ST-7
43 SHB
94
~ \ !
oj ..
44 S.;.5
95
x
45 LSTX
96 ST-9
(/7
RC.8
46 X=8?
.1
47 GT08
98 R.···-S
n
48 ST-:-?
49 ST.;9
*** "Printx" may replace "RIS".
REGISTERS
0 1 2 3 4 5
6
Used
7
LX
4 8
LX
3 9
Lx
2
y,a2
.0
n
.1
LX
.2
LX
2
.3
LY,ao
.4
Used
.5
Lxy,al
16 17
18 19 20 21 22 23
24 25 26 27 28 29
26
PAIRED t-STATISTIC
Given a set of paired observations from
two normal populations with means ~ l ,
~ 2 (unknown)
Yi
let
X2
°i = xi - Yi
1 n
IT = n.L 0i
1 =1
LO.
2
_ 1 {LO.)2
1 n 1
n-l
The test statistic
t = S ~
o
which has n-l degrees of freedom (df) c
can be used to test the null hypothesis
Ho: ~ =
1 2
REFERENCE: Statistics in Research,
B. Ostle, Iowa State
University Press, 1963
EXAMPLE:
x.
1
y.
1
SOLUTION:
14 17.5 17 17.5 15.4
17 20.7 21.6 20.9 17.2
eLI
14.88 ENTt
17.88 bSBl
17.58 ENTt
28.78 bSBl
17.88 E!-ITt
21.68 bSBl
17.58 ENTt
28.98 bSB1
15.48 ENTt
17.28 GSBl
GSB2
-3.28 ftt
IT
R/S
1.88 Ut
So
R.· ..·S
-7.16 ttl;:
t
R ..· .. S
4.88 ftt
df
I
I
[ ,
It
I'
I.
I
i
I
STEP
l.
2.
3.
4.
5.
--
f------
User Instructions
INSTRUCTIONS
INPUT
KEYS
DATA/UNITS
Key in the program
DD
Initialize

Perform 3-4 for i -
1,2, ... ,n
xi I ENTtlD
Yi

1
I
(correct erroneous data)
xk
I
ENTt II
I
Yk

Compute statistics:
I
GSB
II
2
I
I
R/S
II
I

I
R/S
II I
DD
DD
DD
I II I
DD

DD

DD
DI I

-------- L==J
-- ------------_ ..- --- --------
[--] 1---]
------ --- - - -- -
f------- ----------------- --- -------- -- - ------- -------- ---
[- - -- - ] [---- ]
- --- --- - ._._---
I -----1 [----1
27
OUTPUT
DATA/UNITS
i
-
D
So
t
df
--
--------
--------
-----------
---------
------- -- -
---------"-- ---
28
ProgralD Listings
81 *LBLl
Y x
82 -
83 It
84 R/S
85 *LBL2
86 x
87 R/S
*** IT
88 S
89 LSTX
18 Xty
11 R/S
*** S
12 RC.8
D
13 IX
14
15 -
16 R/S
*** t
17 RC.8
18 1
19 -
28 R.··'S
*** df
21 *LBL3
22 -
23 I-
Correct errors
24 R/S
*** "Printx" may e inserted before
or in place f "RIS".
REGISTERS
0 1 2 3 4 5
6 7 8 9 .0
n
.1
LX
.2
Lx
2 .3 .4 .5 16 17
18 19 20 21 22 23
24 25 26 27 28 29
t-STATISTIC FOR TWO MEANS
Suppose Xl, X2, •.• x
nl
and
Yl, Y2, •.. , Yn2 are independent
random samples from two normal popula-
tions having means ~ 1 , ~ 2 (unknown) and
the same unknown variance 0
2
We want to test the null hypothesis
Ho: ~ l - ~ 2 = D
Define
EXAMPLE:
x: 79,
122,
y: 91,
100,
n1 =
8
n2 =
10
84, 108, 114,
120
103, 90, 113,
80, 99, 54
D =
O{i.e.,H
o
: ~ 1
= Jl2)
t =
x - Y - D
~ I + I
~ n2
1
* ...
/ 2 -2 2 -2
EX
i
-nIX +EYi -n
2
y
nl+n2- 2
We can use this t statistic which has
the t distribution with nl + n2 -2
degrees of freedom (df) to test the
null hypothesis Ho.
REFERENCE: Statistical Theory and
Methodology in Science and
Engineering,K.A. Brownlee,
John Wiley & Sons, 1965.
SOLUTION:
CLRb
79.88 1+
84.88 1+
188.88 1+
114.88 1+
128.88 1+
183.88 1+
122.88 1+
128.88 1+
bS81
91.88 1+
183.88 !+
98.88 1+
113. ee 1+
188.88 1+
87.88 1+
188.88 1+
88.88 1+
99.88 1+
54.88 1+
(;582
16.88
u* df
8.88 R/S
D
1.73
u*
t
29
120, 103,
108, 87,
30
User Instructions
STEP INSTRUCTIONS
INPUT
KEYS
OUTPUT
DATA/UNITS DATA/UNITS
1. Key in the program
DD
2. Initialize

3. Perform 3 for i = 1, 2, ... nl xi
0D
i
(correct erroneous data)
x
k

4. Reinitialize GSB
II
1
I
5. Perform 5 for i - 1, 2, ... n2 Yj I+
ID
i
(correct erroneous data)
Yh
f
II
I- I
6. Calculate statistics:
II I
6a. Degrees of freedom

df
6b. Enter D and calculate t statistic D 1 R/S
II I
t
7. For a different D D

t
DI I
DD
I II I
I ID
DI I
DD

DD
1 II I
DD
I II I

- DD
DD
--- I---
I
I II I
31
81 tLBLl
82 RC.8
83 5T04
84 1/X
8S STa1
86 x
87 5T02
88 S
I
89 RG.e
18 1
l'
.l -
12 IX
1J
)(
14 STC3
1S eLI
Reinitia1ize
16 R/S
17 tLBL2
18 RC.e
19 ST+4
28 l/X
21 5T+1
22 .x
23 5T-2
24 5
'?c":
RC.8 .. oJ
26 1
27 -
28 IX
29 x
?8 RCL3
31
~ p
I X2 + y2
32 RCL1
33 RCL4
34 2
3S -
36 R/S
** df
I
Z7 Rl Save D
38
39 IX
48
)(
41 5TOS
Denominator
42 X:Y
D
43 tLBL3
44 RCL2
4S - **
"Printx" may be inserted before "RI
II
46 CHS
47 RCLS
48
49 R.'S
.** t
REGISTERS
0
1 l/nh 1/nl+l/n2/
2
X .x-v
3
Used
4
n1
,nl+n2
5
Denominator
6 7 8 9 .0
.1 LX
n
.2
Lx
2
.3 .4 .5 16 17
18 19 20 21 22 23
24 25 26 27 28 29
32
CHI-SQUARE EVALUATION
This program calculates the value of
the x
2
statistic for the goodness of
fit test by the equation
(0. - E.)2
, ,
E.
,
where O.
,
observed frequency
E. expected frequency
,
If the expected values are equal
LO.
then
(E = E. - -'- for all 1)
, n
X 2 =
n L 0.
2
,
LO.
,
- L O.
,
Note: In order to apply the goodness
of fit test to a set of given data,
combining some classes may be necessary
to make sure that each expected fre-
quency is not too small (say, not 1 ess
than 5).
REFERENCES: Mathematical Statistics,
J.E. Freund, Prentice Hall, 1962
EXAMPLE:
l.
O. 8
,
50 47 56 5 14
E. 9.6 46.75 51.85 54.4 8.25 9.15
,
SOLUTION:
CLRf
8.8t3 fNTt
9.68 GSPl
58.88 fNTt
46.751;SBl
47.88 fNTt
51.85 1;581
56.8e fUn
54.48 GSBl
5.88 fNTt
8.25 GSBI
14.88 fMU
9.15 1;581
6.88 fNTt
9.88 GSB1
6.88 fHTt
9.88 1;5B2
t;SB3
Correct erroneous data
4.84 *** X 2
EXAMPLE:
2. The following table shows the
observed frequencies in tossing a die
120 times. X 2 can be used to test if
the die is fair.
Note: Assume that the expected fre-
quencies are equal.
number 2 3 4 5 6
frequency O. 25 17 15 23 24 16
1
SOLUTION:
CLRt;
25.88 G5Bl
17.8e (;5B1
15.88 t;5Bl
23.88 (;581
24.88 (;SBI
If.B8 (;SBl
33
9.88 (;SBl Correct erroneous data
9.88 (;SB2
(;584
5.88
*u
X2
R··'S
21f. ":U:
E
User Instructions
STEP INSTRUCTIONS
INPUT
KEYS
OUTPUT
DATA/UNITS DATA/UNITS
1 Key in the program
DD
2 Initialize

3 For equal expected values:
DD
3a Perform 3a for i= 1, 2, ... n
O.
1

i
(Correct erroneous data, 0;)
OJ
LciJl
2
I
i
v
3b Calculate X2

X2
3c Calculate E
I R/S
ILJ
E
4 When expected values are unequal:
I II
I
4a Perform 4a-4b for i= 1. 2, ... n
O.
I ENTtlD 1
4b
E.
I GSB II 1 I i 1
.-
(Correct erroneous data, O. , E.)
OJ
IENTtlD
J J
E
j GiJ[LJ
i
4c Ca 1 cu 1 a te X 2
GiJD
y2
5 For a new case 00 to steo 2 I

-------

-----
34 PrograUl Listings
131 *LBLI
e2 srOJ E. or 0.
133
1 1
-
134 X
2
135
,,1'17

e.6
137 ST+2
88 FCLJ
89 1+
113 IVS
i
11 tLBL2
correction routine
12 STOJ
f7
-
""
14 X
2
IS ReLJ
16
17 ST-2
18 PCLJ
19 1-
28
p/s
21 *LBLJ
22 PCL2
23
p,·'s **
X
2
24 fL8L4
2S PC.2
E 0i
2
26 PC.B n
27
x
28 PC.1
EO.
1
29
38 LSTX
.jl -
j, p.····s *** X2
33 .x
34 p.··'s
*** E
** "Printx" may bE inserted before "R \/ 5".
***"Printx" may b inserted before or
in place of "RI 5".
REGISTERS
0 1 2
x
2 3
used
4 5
6 7 8 9 .0 .1
n EX
.2
LX
2 .3 .4 .5 16 17
18 19 20 21 22 23
24 25 26 27 28 29
2 x K CONTINGENCY TABLE
Contingency tables can be used to test
the null hypothesis that two variables
are independent.
2 3 k Totals
A
al a2 a3
a
k
NA
B b
1
b
2
b
3
b
k
NB
Totals Nl N2 N3
Nk
N
Test statistic
N
k
a.
2
N
k
b.
2
x
2
= -
2:
1 +
2:
1
N
NA
i=l
Ni NB
i=l

1
Degrees of freedom df k - 1
Pearson's coefficient of contingency C
measures the degree of association
between the two variables

REFERENCE: Statistics in Research,
B. Ostle, Iowa State University Press,
1963
EXAMPLE:
A
B
2
3
2 3
5
8
4
7
SOLUTION:
CLRt;
2.88 ENTt
3.88 G"SB1
5.88 fNTt
8.88 GSBl
4.88 ENTt
7.88
9.88 fNTt
8.88 GSBI
9.88 EHTt
8.88 GSB2 correct error
R .... S
2.88
***
df
R/8
8.82
***
x
2
R/\$
8.83 tU C
35
36
User Instructions
STEP INSTRUCTIONS
INPUT
DATA/UNITS
KEYS
OUTPUT
DATA/UNITS
1 Key in the program
CC
2 Initialize
Q J ~
3 Perform 3-4 for i= 1, 2, ••. k
a.
1
IENTt I C
b.
4
1
@OI
1
I
i
(correct erroneous data ai' b
i
)
a
j ENTt
I I
b.
GSB
[CJ i
J
5 Calculate degreesof freedom
R/S
I 1
df
6 Calculate x
2
R/S
1 I
x
2
7 Calculate Pearson's coefficient of
~ C
C
contingency
I II 1
CI I
CC
CC
L ~ I I
CC
CI I
CC
CI I
CC
I II I
CC
I II 1
CC
I-
C ~ C
I-- --- CC
1----f--
L ~ I 1
1 11 1
37
81 .LBLl b a
82 I+
83 LSTX b a
84 tLBLB
BS +
N.
1
86 + same in last x
87 RC.2 b
2
88 LST,x
89
18 ST+l
11 RC.4
a
2
12 LSTX
13 .
14 ST+2
IS 8
16 ST.2
17 5T.4
18 RC.B i
19 R/S
28 1
21 -
22 R/S ***df
23 RC.l
NB
24 RC.3
NA
2S + N
26 EHTt
27 STx1
28 STx2
29 CHS
3B RCLl
31 RC.l
32
33 +
34 RCL2
3S RC.3
36
.
37 +
38 R,"S ***x
2
39 +
48 LSTX
41
\ : ' ~ ~ "
II+-l -
42
43 IX
44 R."S
***C
***"Pri ntx.1I be inserted
45 tLBL2 correction routine
may
46 1-
before or in place of "RIS".
47 LSTX
b a
48 bTDB
b.
2
a
i
2 REGISTERS
0 1
1
2 3 4 5
E
Ni
E
N. 6 9 .0
i
.1
NB
1
.2
b
2 .3
NA
.4
a
2 .5 16 17
18 19 20 21 22 23
24 25 26 27 28 29
In the Hewlett-Packard tradition of supporting HP programmable calculators with quality software, the following
titles have been carefully selected to offer useful solutions to many of the most often encountered problems in your
field of interest. These ready-made programs are provided with convenient instructions that will allow flexibility of
use and efficient operation. We hope that these Solutions books will save your valuable time. They provide you with a
tool that will multiply the power of your HP-19C or HP-29C many times over in the months or years ahead.
Mathematics Solutions
Statistics Solutions
Financial Solutions
Electrical Engineering Solutions
Surveying Solutions
Games