Calculators

Reference / Paper · 1982

119 Practical Programs for the TRS-80 Pocket Computer

Read the PDF ↗

John Clark Craig's book of short BASIC programs for the PC-1 and PC-1211 (TAB Books).

Author
John Clark Craig
Year
1982
Type
Reference / Paper
Credit
TAB Books; scan via the Internet Archive.

← Back to the Reference Library

119 Practical Programs for the TRS-80 Pocket Computer

| 1356 H9 PRACTICAL PROGRAMS FOR THE TRS-80° POCKET COMPUTER New techniques for getting the most from your computer’s (lata storage and programming capabilities! BY JOHN CLARK CRAIG N19 PRACTICAL PROGRAMS FOR THE TRS-80° POCKET COMPUTER 119 PRACTICAL PROGRAMS FOR THE TRS-80° POCKET COMPUTER BY JOHN CLARK CRAIG TAB|TAB BOOKS Inc. FIRST EDITION SECOND PRINTING Copyright © 1982 by TAB BOOKS Inc. Printed in the United States of America Reproduction or publication of the content in any manner, without express permission of the publisher, is prohibited. No liability is assumed with respect to the use of the information herein. All-Purpose Driver is a trademark of TAB BOOKS Inc. Library of Congress Cataloging in Publication Data Craig, John Clark 119 practical programs for the TRS-80 pocket computer. Includes index. 1. TRS-80 (Computer)—Programming. 2. Computer pro- grams. |. Title. Il. Title: One hundred nineteen practical pro- grams for the TRS-eighty pocket computer. QA76.8.T18C7 001.64’2 81-18262 ISBN 0-8306-0061-2 AACR2 ISBN 0-8306-1350-1 (pbk.) Contents Introduction Acknowledgments All-Purpose Driver ™ Bernoulli Numbers Bessel Functions Black Holes Boolean Logic Truth Table Calendar—Date Calendar—Easter Calendar—Moon Calendar—Subroutines Calendar—Two Dates Checkbook Chi-Square Circle—Determined by Three X, Y Points Combinations Complex Number Functions Complex Numbers—Simultaneous Equations, Size Two Coordinate Systems for Three Dimensions Coordinate Translation / Rotation Cubic Equations Curve Fit—Exponential Curve Fit—Geometric ix 3 Curve Fit—Linear Curve Fit—Logarithmic Curve Fit— Multiple Linear Regression Curve Fit—Parabolic Decimal to Fraction Conversion Derivatives of a Function Determinant—Two by Two Matrix Determinant—Three by Three Matrix Dice Thrower Differential Equations Distribution—Binomial Distribution—Hypergeometric Distribution—Normal Distribution—Poisson Electronics—Balanced Bridge Electronics—Decibels Electronics—Ohm’s Law Electronics—RC Timing Electronics—Resistor Analysis Electronics—Resonant Frequency Error Function—And Complement Euler Function Euler Numbers EXP (X) for Large X Factorial—Three Versions Factors of a Positive Integer Fibonacci Numbers Flash Cards—Multiplication Table Fractions Games—“Deal ’em” Games—“Huh?” Games—“Lunar Landing” Games—“Numb” Games—‘“Pool” Games—“Wug Hunt” Gamma Function Graphing Helper—Creating a Nice Axis Graphing Helper—Plotting a Function Greatest Common Divisor Gudermannian Function and Inverse Histogram Bins Hyperbolic Functions 117 119 121 123 125 127 131 133 135 137 141 Integrals—Cosine Integral Integrals—Exponential Integral Integrals—Sine Integral Integration—Gaussian Quadrature Integration—Simpson’s Rule Integration—Weddle’s Rule Interpolation—Lagrange Interpolation—Linear Least Common Multiple Limit of a Function Line Analysis Loan Logarithms to Any Base Matrix Inversion Mean and Standard Deviation—Grouped Data Mean and Standard Deviation—Ungrouped Data Means—Arithmetic, Geometric, and Harmonic Metric Conversions Miles Per Gallon Miles Per Hour Moving Average Number Conversions— Binary to Decimal Number Conversions—Decimal to Binary Number Conversions—Decimal to Hexadecimal Number Conversions—Decimal to Octal Number Conversions—Hexadecimal to Decimal Number Conversions—Octal to Decimal Permutations Pl—by Dartboard Plotting—Three Dimensions Pocketext Pocket Alarm Clock Pocket Watch Polar to Rectangular Polygon Area by Walkaround Polygons—Regular Prime Numbers Quadratic Equations Radioisotope Activity Random Numbers—Exponential Distribution Random Numbers—Iintegers from | to J Random Numbers—Normal Distribution 143 145 147 153 155 159 161 163 165 167 169 171 173 177 179 181 183 185 187 189 191 193 195 197 199 201 203 205 209 213 215 217 219 225 227 231 233 235 237 239 241 Random Numbers—Reals from A to B Rectangular to Polar Relativity Simultaneous Equations—Size Two Simultaneous Equations—Size Three Simultaneous Equations—Flexible Size Spherical Triangles Temperature Conversions Triangle Analysis Triangles—in Space Vectors Volume—Defined by Four Cartesian Space Points Wind Chill Index Zero of a Function Appendix A TRS-80 Pocket Computer Reserved Words Appendix B_ Translating to Another BASIC Index 243 245 247 249 251 257 261 263 267 269 281 285 287 290 293 297 Introduction [esa Be LE SP REET he aN The TRS-80 Pocket Computer excellently fills the gap between handheld, programmable calculators and desktop computers! The BASIC computer language is easy to learn and powerful; an im- provement over the non standard methods previously used for the various programmable calculators. And yet, the TRS-80 Pocket Computer is portable enough to be carried into the classroom, laboratory, and meetings, places where a real computer can be very useful. It’s almost an unwritten law that computer programs should be easy to read and as self explanatory as possible. Plenty of REMARK lines, single statements per line, and extra spaces help to achieve these goals in the BASIC language. For desktop computers this approach is appropriate; however, for the TRS-80 Pocket Computer a slightly different philosophy of program design is warranted. This book presents a collection of immediately useful, efficient programs that will allow your TRS-80 Pocket Computer to provide you with quick results. The protected memory feature allows you to load several programs into memory and use them individually as necessary. The fewer steps that each program requires, the more computational power you can have loaded and ready to run! Each program in this book has a label in the first line. And each program terminates with the statement GOTO 1. This is because a special two-line program has been designed to work with all the programs in this book. You may change each GOTO 1 statement to ix an END statement and ignore the labels if you prefer, but at least give this “driver” program a try! It’s the very first program in the book, entitled All Purpose Driver. These programs have been written very compactly. There are ways to squeeze them down even further if desired. Most of the prompting messages can be shortened, as can the program labels. These were not shortened too far for this book in order to keep the programs as understandable as possible. Unclosed parenthesis are allowed on your TRS-80 Pocket Computer. At the expense of readability you could save a few program steps by leaving them open. This collection of programs is a sampling from many different areas of interest. Subjects include games, finance, electronics, statistics, engineering, numerical analysis, and others. The programs cover a wide range of subjects. There should be programs of interest for just about everyone. The programming techniques and ideas presented will help you design and write other similar programs in your areas of interest. Acknowledgments I would like to take this opportunity to extend my thanks to the following people: my wife Jeanie for believing in me, Jennifer and John Adam for being great kids and keeping the television turned down, Bob Carroll for his photographic expertise, and the rest of my family and friends for their advice and encouragement. Most of the illustrations in this book were drawn by some android friends of mine, HP9825A and HP9872A. Thank you both for your after-hours help. And, thank you Anaconda Company for letting them help me. xi All-Purpose Driver ™ Though it is assumed that you have read your manual and are familiar with the operation of your pocket computer, this book will reiterate a few features that are quite useful, or that differ substan- tially from other BASICs. To begin, segments of BASIC code can be labeled by enclosing the label name in quotes immediately after the line number. The label can be any phrase, but if it is a single letter that is reversible, then that segment of code can be executed from the DEF mode by merely typing SHFT and then typing the proper key. Using a key as a label does not prevent you from using it as a reserved word key, and in the RUN, PRO, and RESERVE modes SHFT and the same key will give you the reserved word instead of the branch to the labeled section. You can also say GOTO “label,” but only in a program. ue “Remember that PRINT stops program execution, but using PAUSE instead displays the printout for about a second, and it then continues. USING can be used in the normal manner, to format output, but if it appears at the end of a statement, it clears the display mode. The All-Purpose Driver™ acts as an operating system for BASIC. By ending your programs with GOTO 1, instead of END, and running your programs in the DEF mode, the computer will always return to this operating system at the end of a run, and you can start another program just by typing its label. You can even start the operating system itself by entering the DEF mode and typing SHFT This program makes use of an interesting aspect of the INPUT statement. If the ENTER key is hit with no other input, the com- puter skips the rest of the program line and goes to the next line. This feature is not one usually found in BASIC. Also note that the examples only show the ENTER key when you must hit it and nothing else. It is assumed that you know to hit it after each entry. Every program in this book terminates with the statement GOTO 1. When a program ends, you'll immediately see the > > > in the display again. If you prefer to manually RUN your programs, replace the GOTO 1 statements with END, and erase program lines 1 and 2 from memory. There is one important rule to remember when loading several programs into memory at the same time. Program line numbers must be changed to prevent conflict. The easiest way to do this is by adding a nice round constant amount to each line in a program. For instance, instead of lines 10, 20, and 30, number them 710, 720, and 730 for one program, and 810, 820, and 830 in another. Occasionally you might need to do some calculations and wish to get away from the > > > prompt. Just press ENTER and the driver program will terminate. After your manual calculations are complete, press SHFT and = to return to the > > > prompt. LISTING 1“ ="USING : INPUT” >>> ”; : GOTO Z$ 2END Bernoulli Numbers Psa itis as Rae a a a oe RN aU im Soe Wa Chautala This program computes the Nth Bernoulli Number. For a small N, such as N=1 or N=2, the looping in line 20 will continue for a long time. Line 20 sums the terms of the expansion until a term is small enough that the sum doesn’t change. Notice that the terms will get smaller more rapidly when N is large. Here are the first three Bernoulli numbers: Bi) = 1/6 B(2) = 1/30 B) =1/ 42 For example, what is the 8th Bernoulli number? Display You Enter >>> B ? 8 7.092156862 ENTER >>> Program length is 97 steps. LISTING 10 “B” INPUT N : N=2N :1=0 :X=0 20 I=I+1 : Y=X :X=X+1/1-N : IF X > Y THEN 20 30 M=1 : FOR Z=2 TON : M=MZ : NEXT Z 40 PRINT MX / ( (a * N) * 2“\\N—D) :GOTO1 Bessel Functions This pair of programs computes the Bessel functions Jn(X) and In(X). BSLJ—Computes Jn(X) given n and X. Also computes JO(X) and J1&). BSLI—Computes In(X) given n and X. Example: Compute J4(7. 8) and 13(4. 2). Display You Enter >>> BSLJ FOR JN(X) N? 4 xX? 7.8 J4. ()=—5.571870495 E —02 ENTER JO (X)=2.154078077 E-01 ENTER Jl (X)=2.013568727 E-01 ENTER >>> BSLI FOR IN(X) N? 3 xX? 4.2 13. (X)= 4.211952206 ENTER >>> Program length is 362 steps. LISTING 10 “BSLJ” INPUT“FOR JN(X) N?”,A,“X?”,X : GOSUB 100 :F=1 20 GOSUB 200 : N=N+D : GOSUB 200 : IF I GOTO 20 30 Q=2N-E :J=C/Q :K=E/Q :L=-D/Q 40 PRINT “J’3A;“(X)="3J 50 PRINT “JO ()=";K : PRINT “J1Q)=";L :GOTO1 60 “BSLI’INPUT“FOR IN(X) N?”,A,“X?”,X : F=0 : GOSUB 100 70 N=N+D : GOSUB 200 : IF 1 THEN 70 80 I=C / (2N—E)*EXP (2 / B) : PRINT “T’;A;“()="31 :GOTO1 100 C=3X / 2 :T=A :IF C > A LET T=C 110 I=2+2*INT( (T+6+9C / (C+2)) / 2) 120 B=3/C : E=0 : N=0 :D=E-9 : RETURN 200 I=I-1 : IF A=I LET C=D 210 T=E : IF F LET T=-T 220 E=D : D=T+IBE : RETURN Black Holes This program computes three of four quantities, relating to black holes in space, given any one known quantity. They are; mass in grams, Schwarzchild radius in centimeters, temperature in de- grees Kelvin, and mean liftetime in seconds. Just press ENTER when asked for an unknown. For example: If the mass of the earth was suddenly converted into a black hole, what would it’s Schwarzchild radius, temperature, and expected lifetime be? Display You Enter >>> BH MASS? (GRAMS) 5.983 E27 MASS= 5.9830 £27 GM ENTER RADIUS= 8.8846 E-01 CM ENTER TEMP= 1.6714 E-02 K ENTER LIFE= 2.1416 £55 ENTER >>> Program length is 291 steps. LISTING 10 “BH”CLEAR : INPUT“MASS? (GRAMS)”;M : GOTO 50 20 INPUT“RADIUS? (CM)”;R : GOTO 50 30 INPUT“TEMP? (KELVIN)”;K : GOTO 50 40 INPUT“LIFETIME? (SEC)";L 50 A=1.484986855 E~28 :IFRLET M=R/A 60 IF L LET M=(L / E-28)*(1 / 3) 70 IF K LET M=E26/K 80 R=MA : L= E-28M*3 : K=E26/M : USING’#.4# ###” - 90 PRINT“MASS= ”;M;“ GM” 100 PRINT“RADIUS= ”;R;“ CM” 110 PRINT“TEMP= ”;K;* K” 120 PRINT“LIFE= ”sL;“ SEC” 130 GOTO 1 Boolean Logic Truth Table This program helps you construct a truth table for a Boolean algebra function of your design. You define your function beginning with program line 100. A single result must be returned in variable X. Variables A through V are available for use in the function. The input variables to the function should be sequential and start with A (A, B, and C for the three inputs of our example, for instance). Because of the ability of your TRS-80 pocket computer to return a 1 for “true” and a 0 for “false,” some clever programming steps easily define Boolean functions such as OR, AND, and NOT. For example, the program steps A=0=A provide a convenient NOT A function. If 0=A is true then A will contain 1 after this test, ifO=A is false, A will contain 0. This statement then effectively computes NOT A. Here are several Boolean logic functions expressed in TRS-80 logic form. The rule to remember is that any positive value is true and 0 is false. AND X=AB OR X=A+B NOT X=0=A NAND X=0=AB NOR X=0=A+B XOR X=(A+B)*(AB=0) For example, let’s construct a truth table for the logic circuit of Fig. 1. The equation for this circuit is X=ABC+ABC+ABC+ABC There are several ways to program this function using the TRS-80 logic as described. In this example the variables D, E, and F are first loaded with NOT A, NOT B, and NOT C. Then the final equation is formed from a combination of the variables A through F as in line 110. You must enter the proper number of inputs for the equation you develop; in this case 3. Now that the function is programmed, we're ready to gencrate the truth table. (Fig. 2) Display You Enter >>> BOOL NO. INPUTS? 3 INPUT # 1= 0 INPUT # 2= 0 I Tt o ot oD 1a 1 ago o Itt 1 @1 9 I 109 o a0 8 JVJEHIVHIY «2 GV Jav+JEV Jay+28V +6V28Y Jay+38¥ “+ Big Jav 10 Display You Enter INPUT # 3= 0 X= 0 ENTER INPUT # 1= 0 INPUT # 2= 0 INPUT # 3= 1 X=1 ENTER (etc.) The results should match the truth table in Fig. 2. Program length is 182 steps. LISTING 10 “BOOL’ CLEAR : INPUT“NO. INPUTS?”,Z : USING “###” 20 GOSUB 100 : FOR W=1 TOZ : PAUSE“INPUT #”;W;“=";A(W) : NEXT W 30 X=0< X : PRINT“ X=";X : Y=Z+1 40 Y=Y-1 : IF Y=0 GOTO 1 50 A(Y)=0=A(Y) : IF A(Y) GOTO 20 60 GOTO 40 100 D=0=A : E=0=B :F=0=C 110 X=DEC+DBF+AEF+ABC : RETURN 11 Calendar—Date DESEO NLT a ea ns aa a a This program converts a date from its astronomical Julian day number to month, day, year format. You must also load the calendar subroutines DJ and JD for this program to work correctly. The accuracy range is from October 15, 1582 to February 28, 4000. Also computed is the day of the week for the given date. Example: What day of the week was July 4, 1776? And what is the astronomical Julian day number for this date? (Fig. 3) Display You Enter >>> DATE MONTH? 7 DAY? 4 YEAR? 1776 M. D. Y.=7.4.1776. ENTER AST JULIAN #= 2369916. ENTER WEEKDAY (0=SU 6=SA) IS 4 ENTER >>> Program length, including the necessary subroutines, is 454 steps including subroutines DJ and JD. LISTING 10 “DATE” INPUT“MONTH?”,M, “DAY?”,D,“YEAR?”,Y : GOSUB “DJ” : GOTO 30 20 INPUT“AST JULIAN #?”, J : GOSUB “JD” 30 PRINT“M.D.Y. = ”;M;D;Y : PRINT“AST JULIAN #= ”; J 40 PRINT“WEEKDAY (0=SU 6=SA) IS ”;W : GOTO 1 13 JULY 1776 SUN MON TUE —sOED.—SssSTMUSSFR. SAT 1} 2]; 3} 44 5] 6 144] 15 | 16] 17 | 18 | 19 | 20 21 | 22 | 23 } 24 | 2 | 26 | 27 28 | 29 | 30 | 3l Fig. 3. 14 Calendar—Easter GE aE DLE TE a] This program computes the date of Easter for a given year. The range of accuracy is from the year 1583 to the year 3999. You must also load the calendar subroutines DJ and JD for the program to work correctly. For example: On what date will Easter Sunday be in the year 2106? (Fig. 4) Display You Enter >>> EASTER YEAR? 2106 EASTER= 4.18.2106. ENTER >>> Program length, including the necessary subroutines, is 602 steps. LISTING 200 “EASTER” INPUT“YEAR?”,Y : A=Y/19 : A=Y-19*INT A+1 210 D=14*(A=1)+3*(A=2)+23* (A=3)+11*(A=4)+31*(A=5)+18*(A=6) : IF D GOTO 240 220 D=8*(A=7)+28* (A=8)+16*(A=9)+5*(A=10)+25* (A=11)+13*(A=12) : IF D GOTO 240 230 D=2*(A=13)+22*(A=14)+10* (A=15)+30*(A=16)+17*(A=17)+7*(A=18) +27*(A=19) 240 M=3+(D < 20) : GOSUB “DJ” :J=J+7-W : GOSUB “JD” 250 PRINT “EASTER = ”;M;D;Y : GOTO 1 15 APRIL 21¥6 SUN MON TUE. —SED.—SCsSTHUSCSFR. SST 1} 2] 3 He{ 2} 13) 4] ts | 16] 17 18 | 19 | 2B | el | 22 | 23 | 24 2 | 6 |} 27 | 8b} | BD Fig. 4. 16 Calendar—Moon EEE EE TE This program computes the phase of the moon for any date in the range of October 15, 1582 to February 28, 4000. You must also load the calendar subroutine DJ for this program to work correctly. For example: Describe the moon on June 25, 1982. (Fig. 5) Display You Enter >>> MOON DATE M? 6 D? 25 y? 1982 MOON LIT ABOUT 027 —«-ENTER HEADED FOR A NEW MOON.ENTER >>> Program length, including the necessary subroutine, is 349 steps. LISTING 100 “MOON” INPUT“DATE M?”,M,“D?",D,“¥2”,Y : GOSUB “DJ” 110 M=(+4.867) / 29.53058 : M=2*(M-INT M)-1 : N=ABS M 120 USING “##, ##” : PRINT“MOON LIT ABOUT ”;N 130 Z$=“NEW” : IF M LET Z$=“FULL” 140 PRINT“HEADED FOR A ”;2$;“ MOON.” :GOTO1 17 Moon Phase "MOON LIT ABOUT . 27" "HEADED FOR A NEW MOON, " Fig. 5. 18 Calendar— Subroutines eT A These subroutines are used by several calendar-related pro- grams in this book. DJ—Converts a date expressed as month, day, and year in variables M, D, and Y to the equivalent astronomical Julian day number. This day number is returned in variable J. JD—Converts an astronomical Julian day number in variable J to the equivalent month, day, and year for that date. Variables M, D, and Y are returned with these values. Both subroutines also return the day of the week in variable W. 0 for Sunday, 1 for Monday, and so on through 6 for Saturday. These subroutines are quite powerful for many calendar re- lated computations. The number of days between dates can be found by subtracting their astronomical Julian day numbers. A date’s validity can be checked by calling first “DJ” and then “JD” and comparing the resulting values of M, D, and Y with the original values. The range of accuracy is from October 15, 1582 (the day the Gregorian calendar began) to February 28, 4000. Be careful with dates earlier than the 1700s, however, as some countries were using calendars that differed by several days from each other. Program length is 303 steps. LISTING 900 “DJ”J=INT(365.2422Y+30.44*(M—1)+D+1) : N=M—2+12*(M < 3) 905 Z=Y—(M < 3) : E=INT (Z / 100) : Z=Z—100E 910 W=INT(2.61N—.2)+D+Z+INT(Z / 4)+INT(E / 4)—2E 915 W=W-—7*INT(W / 7) : X=J—7*INT( / 7) 920 J=J—X+W-—7*(X < W)+1721061 : RETURN 950 “JD”G=J : Y=INT ( J—1721061) / 365.25+1) : M=1 : D=1 19 955 GOSUB “DJ” : IF] > G LET Y=Y-1 : GOTO 955 960 M=INT ( (G-J) / 29+1) 965 GOSUB “DJ” : IF] > G LET M=M-1 : GOTO 965 970 D=G—J+1 : GOTO “DJ” 20 Calendar—Two Dates This program may be used in two ways. If you input two dates the number of days between them will be computed. Or, if you input a date and a number of days to add to it, the second date will be computed. Accuracy range is from October 15, 1582, to February 28, 4000. Example: How many days until Christmas on November 16, 1982? Display You Enter >>> 2DATES FIRST DATE M1? 11 DIP 16 YL? 1982 2ND DATE M2? 12 D2? 25 Y2? 1982 39. DAYS BETWEEN ENTER >>> Program length is 494 steps. LISTING 50 “2DATES”INPUT“FIRST DATE M1?”,M,“D1?”,D,“Y1?”,Y : GOSUB “DJ” 60 A=J : INPUT“2ND DATE M2?”,M, “D2?”,D,“Y2?”,Y : GOSUB “DJ” : GOTO 90 70 INPUT“# DAYS FROM DATE?”,N : J=J+N :GOSUB “JD” 80 PRINT“NEW M.D.Y.=”;M;D;Y :GOTO1 90 PRINT J~A;“DAYS BETWEEN” : GOTO 1 21 Checkbook EE a ae TS TS This program will help you balance your checkbook. Start by entering the beginning balance. Then, for every check or deposit that has cleared the bank (is listed in the bank statement) enter the amount when asked. To bypass any questions, just press ENTER. An uncleared check or deposit is one that you have written down in your checkbook but is not noted on the bank statement. To see the balance so far, bypass all the questions until the balances are shown. The program will always branch back to the “CHECK?” question Display You Enter >>> CHECKS BEGINNING BALANCE? 100 CHECK? 25 CHECK? ENTER DEPOSIT? 10 CHECK? ENTER DEPOSIT? ENTER UNCLEARED CHECK? 60 CHECK? ENTER DEPOSIT? ENTER UNCLEARED CHECK? ENTER UNCLEARED DEPOSIT? ENTER BEEP BOOK SHOULD SAY 25.00 ENTER BEEP BANK SHOULD SAY 85.00 ENTER CHECK? (etc.) Program length is 243 steps. LISTING 10 “CHECKS USING # #####. ##” : INPUT“BEGINNING BALANCE?”,A : B=A 20 INPUT“CHECK? ”,C : A=A-—C : B=B-C : GOTO 20 30 INPUT“DEPOSIT? ”;D : A=A+D 23 : B=B+D : GOTO 20 40 INPUT “UNCLEARED CHECK? ”;E : A=A-E : GOTO 20 50 INPUT“UNCLEARED DEPOSIT? ”;F : A=A+F : GOTO 20 60 BEEP 1 : PRINT“BOOK SHOULD SAY”;A 70 BEEP 1 : PRINT“BANK SHOULD SAY”;B : GOTO 20 24 Chi-Square This program computes the Chi-square statistic for a group of observed frequencies and their expected frequencies. Example: Compute the Chi-square statistic for the following data. Observed frequency 6 12 15 Expected frequency 10 10 10 Display You Enter >>> CHI OBS FREQ? 6 EXP FREQ? 10 OBS FREQ? 12 EXP FREQ? 10 OBS FREQ? 15 EXP FREQ? 10 OBS FREQ? ENTER CHI“2= 4.5 ENTER >>> Program length is 76 steps. LISTING 10 “CHI’CLEAR 20 INPUT“OBS FREQ?”,X,“EXP FREQ?”,E : A=A+XX / E-2X+E : GOTO 20 30 PRINT“CHI*2= ”;A :GOTO1 25 Circle—Determined By Three X, Y Points This program computes and describes a circle that passes through three given X, Y points. For example: What circle passes through the points (3, 12), (10, 13), and (7, 4)? (Fig. 6) Display You Enter >>> CIR Xl? 3 Yl? 12 X2? 10 Y2? 13 X3? 7 Y3? 4 RADIUS= 5. ENTER CENTER (X,Y) — > ENTER 7. 9. ENTER AREA= 78.53981634 ENTER >>> Program length is 243 steps. LISTING 10 “CIR” INPUT“X1?”,A,“Y1?",B,“X2?”, C,“¥2?”,D,“X3?”,E,“Y3?",F 20 K=(EE+FF-AA—BB) / 2 / (E—A) : L=(EE+FF-CC-DD) / 2 / (E-C) 30 N=(B-F) / (A-E) : P=(D-F) / (C-E) : Y=(L-K) / (P-N) : X=L-PY : T=C-X : U=D-Y : R= V (TT+UU) : V=7RR 40 PRINT“RADIUS= ”;R : PRINT“CENTER (X,Y) - >” 50 PRINT X, Y : PRINT“AREA= ”;V :GOTO1 27 16 14 12 10 B Circle Determined by Three Points (10, 13) (3 12) Area = 78.93981634 q, 4) Fig. 6. 28 Combinations ERED SE EO This program computes the number of combinations possible from Y objects taken X at a time. For example: How many combina- tions of 5 objects taken 3 at a time are possible? (Fig. 7) Display You Enter >>> co ? 5 ? 3 10. ENTER >>> Program length is 71 steps. LISTING 10 “CO”INPUT Y,X : C=Y : IF Y-X > X LET X=Y-X 20 FOR Z=1 TO X :C=C/Z : IF Y-Z > Y-X LET C=CY-—CZ 30 NEXT Z : PRINT C : GOTO 1 29 Combinations o 5 ob jects taken 3 at atime... 10 combinations Fig. 7. 30 Complex Number Functions This is a collection of nine programs for complex number analysis. A sample run of each program will help clarify their use. C+ (A1+iB1) + (A2+iB2) Cc- (A1+iB1) — (A2+iB2) c* (A1+iB1) * (A2+iB2) C/ (A1+iB1) / (A2+iB2) 1/C 1/(A+iB) RP (A+iB) converted to (R,A). “Rectangular to Polar”. PR (R, A) converted to (A+iB). “Polar to Rectangular”. C2 (A+iB) squared. VC Square root of (A+1B). Results are always returned in variables A and B. To use the results in a computation enter A when asked for Al?, and B when asked for B1?. This is demonstrated in some of the examples. Compute (3+i4) + (2—-i7). Display You Enter >>> C+ Al? 3 BI? 4 A2? 2 B2? -7 5. -3. ENTER >>> The answer is (5—i3). Now subtract 3 from this result. Display You Enter >>> c- Al? A Bl? B A2? 3 B2? 0 2. -3. ENTER >>> The answer is (2—i3). Compute 12 * (3+i4). 31 The answer is (—8+i6). Compute (8—i6) / (3+i4). Display >>> Al? Bl? A2? B2? —8. 6. >>> Display >>> Al? BI? A2? B2? 0. -2 >>> The answer is (—i2). Compute 1 / (3+i4). Display >>> A? B? 0.12 -—0.16 >>> A? B? 3. 4. >>> You Enter c* You Enter c/ 8 -6 3 4 ENTER You Enter 1/C 3 4 ENTER (.12—i.16) is the answer “1/(C” (Let’s check our answer.) A B ENTER (Looks good.) Convert (3+i4) to polar notation, then back to rectangular. DEG mode is set. 32 Display >>> A? B? 5. 53.13010235 You Enter RP 3 4 ENTER >>> A? B? 3. 4. >>> PR 5 53.13010235 ENTER Compute (3—i4) * (3-4), then find the square root of the result. Display >>> A? B —7. —24. >>> A? B? 3. 4. >>> Program length is 502 steps. LISTING 10 “C+”GOSUB 200 : A=A+C : B=B+D : GOTO 250 20 “C—”GOSUB 200 : A=A-—C : B=B-D : GOTO 250 30 “C*”GOSUB 200 : A27)=AC-—BD : B=AD+BC : A=A(27) : GOTO 250 40 “C /”GOSUB 200 : A(27)=AC+BD : A28)=CC+DD : B=(BC—AD) / A(28) : A=A(27) / A(28) : GOTO 250 50 “1 / C’GOSUB 230 : A(27)=AA+BB You Enter c2 3 -4 ENTER (—7-i24) VC A B ENTER 33 : A=A/ AQ7) : B=-B/ A227) : GOTO 250 60 “RP”GOSUB 230 : AQ7)= V (AA+BB) : A=(28)=ACS(A / AQ) 65 B=A(28)*SGN B+A(28)*(B=0) : A=AQ27) : GOTO 250 70 “PR”’GOSUB 230 : A(QQ)=A*COS B : B=A*SIN B : A=A(27) : GOTO 250 80 “C2”GOSUB 230 : A(27)=AA- BB : B=2AB : A=AQ7) : GOTO 250 90 “ V C’GOSUB 230 > A= V( (A+ V (AA+BB)) / 2) :B=B/A/2 : GOTO 250 200 INPUT“A1?”,A,“B1?”,B 210 INPUT“A2?”,C,“B2?”,D 220 RETURN 230 INPUT“A?”,A,“B?”,B 240 RETURN 250 PRINT A,B : GOTO 1 Complex Numbers— Simultaneous Equations, Size Two This program solves a pair of simultaneous equations for the two complex unknowns. Example: Solve for X and Y. (1+i2)X +Y = (4-i) (-)X +(2+i3)Y = 1 Rewritten ... (1+i2)X + (1+i0)Y = (4-il) (0-iDX + (2+i3)Y = (1+i0) Display You Enter >>> CSE2 REAL? IMAG? REAL? IMAG? REAL? IMAG? REAL? IMAG? REAL? IMAG? REAL? IMAG? 0.5 —1.5 ENTER 0.5 -0.5 ENTER >>> Or, X = (.5-i1.5) and Y = (.5-i.5) Program length is 215 steps. LISTING 10 “CSE2”FOR X=1 TO 6 : Z=2X : Y=Z-1 : INPUT“REAL?”,A(Y),“IMAG?”,A(Z) : NEXT X 20 M=AI—BJ-CG+DH : N=AJ+BI-CH-DG an OrPwns] oo] RoOHNH 35 :0=EI-FJ-CK+DL :P=EJ+FI-CL—DK 30 Q=AK—BL—EG+FH : R=AL+BK—EH-—FG : S=MM+NN : T=0M /S+PN/S U=PM /S-ON/S 40 PRINT T,U : V=QM /S+RN/S : W=RM / S-QN/S : PRINT V,W : GOTO 1 36 Coordinate Systems for Three Dimensions This program translates coordinates in space between all three commonly used coordinate systems. (Fig. 8) There are three labels to activate this program. REC~—Ifthe given coordinates are in rectangular notation, (X, Y, Z). CYL—Ifthe given coordinates are in cylindrical notation, (R, Theta, 2). SPH—If the given coordinates are in spherical notation. (Rho, Theta, Phi). Any angular mode is okay to use. For example: Convert the rectan- gular coordinates (3, 4, 5) to the other coordinates systems. DEG mode is set. Display You Enter >>> REC X? 3 Yy? 4 2 5 REC - > ENTER X=3. ENTER =4 ENTER Z=5. ENTER CYL— > ENTER R= 5. ENTER THETA= 53.13010235 ENTER Z= 5. ENTER SPH — > ENTER RHO= 7.071067812 ENTER THETA= 53.13010235 ENTER PHI= 45. ENTER >>> Program length is 350 steps. 37 7 YD Rectangular Coordinates Cylindrical Coordinates Spherical Coordinates Fig. 8. 33 LISTING 10 “CYL” INPUT“R?”,R,“THETA?”,T,“Z?”,C 20 X=R*COS T : Y=R*SIN T : GOTO 200 30 “SPH” INPUT“RHO?”,H,“THETA?”,T, “PHI?”,P 40 X=H*COS T*SIN P : Y=H*SIN T*SIN P : C=H*COS P : GOTO 200 50 “REC”INPUT“X?”,X,"¥2”,Y,“Z?”,C 200 R= V (XX+YY) : T=ACS(X / R) : T=T*SGN Y+T*(Y=0) 210 H= V (XX+YY+CQ) : P=ACS(C/ H) 220 PRINT“REC — >” : PRINT“X= ":X : PRINT“Y= ”;Y : PRINT“Z= ”;C 230 PRINT“CYL ~ >” : PRINT“R= ;R : PRINT“THETA= ”;T : PRINT“Z= ";C 240 PRINT“SPH —>” : PRINT“RHO= ";H : PRINT“THETA= ";T : PRINT“PHI= ”;P 250 GOTO 1 39 Coordinate Translation / Rotation This program translates X, Y points from an old coordinate system to a new coordinate system. The origin of the new coordi- nate system, expressed as a point in the old system, and the angular rotation of the systems relative to each other are first input. Then, for every X, Y point from the old coordinate system, the translated X, Y equivalent point in the new system is computed. Example: A new coordinate system has it’s origin at (9, 14) and is rotated 20 degrees as measured in the old coordinate system. (Fig. 9) What are the new coordinates for the point (17, 25)? Display You Enter >>> CTR FOR NEW ORIGIN, X? 9 Y? 14 ROTATION ANGLE? 20 OLD X? 17 Y? 25 11.27976254 7.600457683 ENTER OLD X? ENTER >>> Program length is 127 steps. LISTING 10“CTR”INPUT“FOR NEW ORIGIN, X?”,A,“Y?”,B,“ROTATION ANGLE?”,R : S=SINR : K=COS R 20 INPUT“OLD X?”,X,“Y?”,Y : D=AS—XS+YK-—BK : PRINT XK~AK+YS—BS, D : GOTO 20 30 GOTO 1 41 Coordinate Translation/Rotation } 0 4 san rica * 1, -10 Fig. 9. 42 30 "Old" Coordinate System Cubic Equations This program computes the real or complex roots of a cubic equation. For example: Compute the roots for X*3 +5X°2—2X—24 =0 Display You Enter >>> CUB AX*3+BX°2+CX+D=0 ENTER A? 1 B? 5 Cc? -2 D? —24 REAL ROOT= 2. ENTER REAL ROOT= —4. ENTER REAL ROOT= —3. ENTER >>> Program length is 405 steps. LISTING 10 “CUB”PRINT“AX*3+BX°2+CX+D=0” : INPUT“A?”,A,“B?”,B,“C?”,C,“D?”,D 20 Q=(3C-BB / A) / 9A : R=(9BC / A~27D-2BBB / A/ A) / 54A : U=QQQ+RR 30 IF U > =0 LET P=1/3 :S=R+ VU : S=SGN S*ABS S*P :T=R- VU : T=SGN T*ABS T*P :G=S+T-B/3/A : GOTO 50 40 Q=-Q : G=2* V Q*COS(ACS(R/ VQQQ)/3)-B/3/A 50 PRINT“REAL ROOT= ”;G : E=G+B/A : C=GG+GB/A+C/A : B=E :A=1 43 60 D=(BB-4AC) /4/ AA :E=-B/2/A : F= V ABS D 70 IF DLET S=E-F : Z=E+F : PRINT“REAL ROOT= ”;S : PRINT“REAL ROOT= ”:Z : GOTO 1 80 PRINT“COMPLEX ROOTS FOLLOW” : PRINT“REAL PART= ";E : PRINT“+ /- @) =";F :GOTO1 44 Curve Fit— Exponential ee a a This program uses the least squares method to fit an exponen- tial equation (Y=A*EXP (BX)) to a set of given X,Y points. Example: Fit an exponential curve to the following data. X 1.712 Y¥ 3.66 12.2 33.1 Display You Enter >>> CFE BEEP X? aA Y? 3.66 BEEP x? 7 Y? 12.2 BEEP X? 1.2 Y? 33.1 BEEP xX? ENTER Y=A*EXP(BX) ENTER A=2.998519512 ENTER B= 2.002038184 ENTER R°2= .9999977889 ENTER NEW X? 1 22.20143341 ENTER NEW X? ENTER >>> Program length is 202 steps. LISTING 10 “CFE”CLEAR 20 BEEP 1 : INPUT“X?”,X,“Y?”,Y : Y=LN Y : C=C+X : D=D+XX : E=E+Y 45 : F=F+YY : G=G+XY :T=I+1 : GOTO 20 30 J=GI- CE : B=J / (DI-CC) : A=EXP ((E—BC) /D) : R=BJ / (FI-EE) 40 PRINT“Y=A*EXP (BX)” : PRINT“A= "3A : PRINT“B= ”;B : PRINT“R‘2= ”;R 50 INPUT“NEW X?”,X : PRINT A*EXP BX : GOTO 50 60 GOTO 1 46 Curve Fit— Geometric Be SD Ss SNE A TN Hs AT ree na eae This program uses the least squares method to fit a geometric equation (Y=A*X“%B) to a set of given X, Y points. Example: Fit a geometric curve to the following data. X 1.516 1.718 ¥ 2.11714 12 Display You Enter >>> CFG BEEP X? 1.5 Y? 2.1 BEEP xX? 16 Y? 17 BEEP xX? 17 Y? 14 BEEP xX? 18 Y? 1.2 BEEP xX? ENTER Y=A*X*B ENTER A=7.287529642 ENTER B= —3.086087334 ENTER R°2= .9981553113 ENTER NEW X? 14 2.579980683 ENTER NEW X? ENTER >>> Program length is 203 steps. LISTING 10 “CFG” CLEAR 20 BEEP 1 : INPUT“X?”,X,“Y?”,Y 47 : X=LN X : Y=LN Y : C=C+X : D=D+XX : ESE+Y : F=F+YY : G=G+XY :I=I+1 : GOTO 20 30 J=GI-CE : B=J / (DI-CQ) : A=EXP ((E-BC) / 1) : R=BJ / (FI- EE) 40 PRINT“Y=A*X*B” : PRINT“A= "5A : PRINT“B= ”;B : PRINT“R“2= ”;R 50 INPUT“NEW X?”,X : PRINT A*X*B : GOTO 50 60 GOTO 1 48 Curve Fit—Linear This program uses the least squares method to fit a linear equation (Y=A+BX) to a set of given X,Y points. Example: Fit a linear curve to the following data. ».¢ 1 2 3 Y 1 19 3.1 Display You Enter >>> CFL BEEP X? 1 y? 1 BEEP X? 2 Y? 19 BEEP xX? 3 y? 3.1 BEEP xX? ENTER Y=A+BX ENTER =-0.1 ENTER B= 1.05 ENTER R°2= .9932432432 ENTER NEW X? 4 4.1 ENTER NEW X? ENTER >>> Program length is 188 steps. LISTING 10 “CFL”CLEAR 20 BEEP 1 : INPUT“X?”,X,“Y?”,Y : C=C+X : D=D+XX : E=E+Y : F=F+YY : G=G+XY 49 : I=I+1 : GOTO 20 30 J=GI-CE : B=J / (DI-CQ) : A=(E-BQ) /I : R=BJ / (FI-EE) 40 PRINT“Y=A+BX” : PRINT“A= "3A : PRINT“B= ”;B : PRINT“R*2= ”";R 50 INPUT“NEW X?”,X : PRINT A+BX : GOTO 50 60 GOTO 1 50 Curve Fit—Logarithmic LL TNT EN IT ITY This program uses the least squares method to fit a logarithmic equation (Y=A+B*LN X) to a set of given X,Y points. Example: Fit a logarithmic curve to the following data. xX 1 2 3 4 Y 5 78 94 10 Display You Enter >>> CFLN BEEP xX? 1 Y? 5 BEEP X? 2 yY? 78 BEEP xX? 3 y? 94 BEEP xX? 4 Y? 10 BEEP Xx? ENTER Y=A+B*LN X ENTER A= 5.109167233 ENTER B= 3.701425997 ENTER R°2= .9909435456 ENTER NEW X? 5 11.06638256 ENTER NEW X? ENTER >>> Program length is 200 steps. LISTING 10 “CFLN”CLEAR 20 BEEP 1 : INPUT“X?”,X,“Y?”,Y 51 : X=LN X : C=C+X : D=D+XX : E=E+Y : F=F+YY : G=G+XY :I=1+1 : GOTO 20 30 J=GI-CE : B=J / (DI-CC) : A=(E-BC) /1 : R=BJ / (FI-EE) 40 PRINT“Y=A+B*LN X” : PRINT“A= ”;A : PRINT“B= ”;B : PRINT“R*2= ”;R 50 INPUT“NEW X?”,X : PRINT A+B*LN X : GOTO 50 60 GOTO 1 52 Curve Fit— Multiple Linear Regression This program computes an equation of the form “Z=A+ BX+CY” by the least squares method for a given set of three dimensional points (X,Y,Z). Example: Compute an equation that most closely relates the follow- ing data by an equation of the form Z=A+BX+CY. x Y Z Display >>> BEEP xX? y? 2? BEEP xX? Y? 2 BEEP xX? Y? 2? BEEP xX? Z=A+BX+CY A= 2. B= 2. =—3. >>> Program length is 270 steps. LISTING 10 “MLR”CLEAR : GOTO 30 20 D=D+Y : ESE+YY 2 3 2 1 0 5 You Enter MLR Per Oe OO ont ENTER ENTER ENTER ENTER ENTER 53 : F=F+XY : G=G+Z : H=H+XZ : I=I+YZ 30 BEEP 1 : INPUT“X?”,X,“Y?”, Y,“Z?",Z : A=A+1 : B=B+X : C=C+XX : GOTO 20 40 M=(AC- BB)*(AI- DG) : N=(AF-—BD)*(AH-BG) 50 L=(M—N) / (AC-BB)*(AE- DD)—(AF-BD)*2) 60 K=(AH—BG—L*(AF—BD)) / (AC-BB) : J=(G-LD-KB)/A 70 PRINT“Z=A+B+CY” : PRINT“A= ”;J : PRINT“B= ”;K : PRINT“C= ”;L : GOTO 1 Curve Fit— Parabolic This program uses the least squares method to fit a parabolic equation (Y=A+BX+CX*2) to a set of given X,Y points. Example: Fit a parabolic curve to the following data. x 0 Y ll Display >>> BEEP xX? Y? BEEP xX? Y? BEEP xX? y? BEEP xX? y? BEEP xX? Y=A+BX+CX*°2 A= 1.12 B= 0.92 C=1 R*2= .9999010391 NEW X? 20.8 NEW X? >>> Program length is 337 steps. LISTING 10 “CFP”CLEAR : GOTO 30 20 H=H+XXXX : I=I+Y 2 3 6.9 12.9 You Enter CFP 0 11 1 3.1 2 6.9 3 12.9 ENTER ENTER ENTER ENTER ENTER ENTER ENTER ENTER 55 : J=J+XY : K=K+XXY : L=L+YY 30 BEEP 1 : INPUT“X?”, X,“Y?”,Y : D=D+1 : E=E+X : F=F+XX : G=G+XXX : GOTO 20 40 M=DFH+2EGF- FFF—EEH- DGG : A=(HFI+EGK+FJG—FFK—EJH-IGG) /M 50 B=(DJH+IGF+FEK~—FJF-IEH—-DGK) /M :C=(DFK+EJF+IEG—FFI-EEK—DJG) / M 60 R=(AI+BJ+CK-II / D) / (L—II / D) : PRINT“Y=A+BX+CX‘2” 70 PRINT“A= ”;A : PRINT“B= ”;B : PRINT“C= ”;C : PRINT“R*2= ”;R 80 INPUT“NEW X?”,X : PRINT A+BX+CXX : GOTO 80 90 GOTO 1 56 Decimal to Fraction Conversion aL I ee This program computes successively more accurate fractions as approximations to a decimal number X. For example: Approximate the value of PI with fractions. Display >>> ? 3./1. ERR= —0.141592654 22./ 7. ERR= 1.26448885 E—03 333. / 106. ERR= —8.322004 E—05 355. / 113. ERR= 2.6635 E—07 (etc.) Program length is 130 steps. LISTING 10 “DF’INPUT X : A=INT X :B=1 : C=X-A : D=0 : E=1 :F=1 : G=0 20 H=AF+D : I=AG+E : Y=H /I-X : PRINT H;“ / ”3I : PRINT“ERR = ”;Y 30 A=INT (B / C) :J=C : C=B—AC : B=J : D=F : F=H You Enter DF 7 ENTER ENTER ENTER ENTER ENTER ENTER ENTER ENTER 57 : E= :G= : GOTO 20 Derivatives of a Function RS a I a ES This collection of three programs computes the Oth, 1st, and 2nd derivatives of a user defined function “FX”. The Oth derivative is just the function itself, the 1st derivative is the slope of the function, and the 2nd derivative relates to the curvature. A small delta increment of .0001 may optionally be altered when asked for D? Example: Analyze the function Y=X° at X=1. First, verify that the function FX has been programmed as in line 900. Display You Enter >>> DO xX? 1 F®=1. ENTER >>> Dl x? 1 D? ENTER DX= 3.000005 ENTER >>> D2 xX? 1 D? ENTER DDX= 6. ENTER >>> Program length is 231 steps. LISTING 10 “DO” INPUT“X?”,X : GOSUB“FX” : PRINT“F)= ”3Y : GOTO 1 20 “D1”D=E—4 : INPUT“X?”,W,“D?”,D 30 FOR E=1 TO 2 : X=W+DE-—3D / 2 : GOSUB“FX” : A(E)=Y : NEXT E 59 40 Z=(B-A) /D : PRINT“DX= ”;Z : GOTO 1 50 “D2”D=E—4 : INPUT“X?”,W,“D?”,D 60 FOR E=1 TO 3 : X=W+DE-2D : GOSUB“FX” : A(E)=Y : NEXT E 70 Z=(A+C-2B) / DD : PRINT“DDX= ”;Z : GOTO 1 900 “FX” Y=XXX :RETURN 60 Determinant—Two by Two Matrix This program computes the determinant of a four element square matrix (2 by 2). For example, compute the determinant of the following matrix. 1 2 3 -4 Display You Enter >>> DT2 ? 1 ? 2 ? 3 ? -4 -10. ENTER >>> Program length is 26 steps. LISTING 10 “DT2”INPUT A,B,C,D : PRINT AD-BC :GOTO1 61 Determinant — Three by Three Matrix SI BSS ESCA ED SI UIT DOSEN I SSN This program computes the determinant of a nine element square matrix (3 by 3). For example, compute the determinant of the following matrix. 1 2 3 12 0 -1 -2 4 2.7 Display You Enter >>> DT3 ? 1 ? 2 ? 3 ? 1.2 ? 0 ? -1 ? -2 ? 4 ? 2.7 15.92 ENTER >>> Program length is 54 steps. LISTING 10 “DT3”INPUT A,B,C,D,E,F,G,H,I : PRINT AEI+BFG+CDH—CEG-BDI- AFH : GOTO 1 63 Dice Thrower This program rolls a pair of pseudorandom dice. Use the ON / BREAK key to terminate the program. Display You Enter >>> DICE 2.1, ENTER 2.5. ENTER 1.4. ENTER 11. ENTER 6.3. ENTER 4.2. ON / BREAK BREAK AT 10 Program length is 62 steps. LISTING 10 “DICE”GOSUB“R” : A=1+INT 6R : GOSUB“R” : PRINT 1+INT 6R;A : GOTO 10 20 “R”’R= 7 +983R : R=R-INTR : RETURN 65 Differential Equations SSS a This program computes a numerical solution for differential equations by the Runge-Kutta method. The differential equation should be in the form Y’=f(X,Y). FX is the label to use where you program your equation. Use Z in place of Y’ as the return variable. Example: Compute a solution to Y'=X+Y given initial conditions of X=0 and Y=0. Use an increment of .5. Display >>> X0? YO? INC? 0.5 0.1484375 1. 0.717346 15 1.979375363 2. 4.383970325 2.5 8.672013583 (etc.) Program length is 171 steps. LISTING You Enter DE 0 0 5 ENTER ENTER ENTER ENTER ENTER 10 “DE” INPUT“X0?”,V,“Y0",W,“INC?”,I 20 X=V : Y=W : GOSUB“FX” : A=IZ > X=V+I/2 : Y=W+A /2 : GOSUB“FX” : B=IZ : Y=W+B /2 : GOSUB“FX” 30 C=IZ ?X=V+I : Y=W+C : GOSUB:“FX” : D=IZ : V=V+I 67 : W=W+(A+2B+2C+D) / 6 : PRINT V,W : GOTO 20 900 “FX”Z=X+Y : RETURN 68 Distribution—Binomial BEA PSE SPOS RE ES RARE eT This program computes the binomial distribution function given X, n, and p. b(X5n,p) = p* (1-p)"* n! X! @—X)! Example: Compute the binomial distribution function for X=9, n=10, and p=.8. Display You Enter >>> BIN xX? 9 N? 10 P? 8 268435456 ENTER >>> Program length is 115 steps. LISTING 10 “BIN”INPUT“X?”,X,“N?”,N,“P2”,P 20 A=N : B=X :C=A : IF A-B > B LET B=A-B 30 FOR Z=1 TO B :C=C/Z : IF A~Z > A-B LET C=CA-CZ 40 NEXT Z : PRINT P*X*(1—P)*(N- X)*C : GOTO 1 69 Distribution—Hypergeometric This program computes the hypergeometric distribution func- tion given X, sample size n, population or lot size N, and “success- es”