Post Reply 
(Sharp PC-1261) Poisson, Binomial, Negative Binomial Distributions
05-11-2021, 05:53 PM (This post was last modified: 05-11-2021 06:06 PM by Dave Britten.)
Post: #1
(Sharp PC-1261) Poisson, Binomial, Negative Binomial Distributions
I picked up a Sharp PC-1261 this week, and it's a pretty neat little machine. It's sort of like a fancied up PC-1250 (Tandy PC-3), with a two-line display, ~10 KB RAM, and a cool built-in help system that lists all the commands and functions, and even provides simple usage examples of each. It uses the more sophisticated BASIC seen on later models, with two-character variable names. This means that PC-1211 programs aren't directly compatible like they are on the PC-1250, but they can usually be made to work with only some simple changes.

This program calculates the Poisson, binomial, and negative binomial distributions, and uses the CURSOR instruction to take advantage of the two-line display. It also demonstrates SHARP's clever use of the INPUT instruction as a conditional (pressing ENTER without actually entering anything leaves the input variable unchanged and also skips the remainder of the line).

Binomial Distribution

RUN "BINOM"

Inputs
N: Number of trials
P: Probability of success in one trial
L: Minimum number of successes
H: Maximum number of successes

Total probability will be displayed. If L<>H, then you'll get a cumulative probability for L<=x<=H.

Negative Binomial Distribution

RUN "NBINOM"

Inputs
NEED: Number of successful trials needed
P: Probability of success in one trial

The program will calculate the probability for NEED-1 successes in R-1 trials, followed by a success in trial number R, for increasing values of R. The first calculation will be for R=NEED. The program displays R, P(x=R), P(x<=R), and P(x>R).

Press Enter at the "QUIT?" prompt to increment R and display the new results. To quit, type any character at the prompt before pressing Enter.

Poisson Distribution

RUN "POIS"

Inputs
LAMBDA and X, the standard Poisson distribution variables.

Outputs
F(X) - Probability density
P(X) - Cumulative lower-tail probability (x<=X)

The program will prompt for LAMBDA once, and then repeatedly prompt for values of X. To quit the program, press Enter at the "X?" prompt without typing anything.

Code:
200 "POIS" INPUT "LAMBDA?";L
201 Z= EXP -L
202 INPUT "X?";X: GOTO 204
203 END
204 F=Z:P=Z
205 IF X<1 GOTO 207
206 FOR I=1 TO X:F=F*L/I:P=P+F: NEXT I
207 WAIT 0: PRINT "F(X)=";F;: CURSOR 24: WAIT : PRINT "P(X)=";P: GOTO 202
210 "BINOM" INPUT "N?";N
211 INPUT "P?";P
212 INPUT "L?";L
213 INPUT "H?";H
214 S=(1-P)^N:R=0:T=0
215 IF R>=L LET T=T+S
216 IF R>=H GOTO 218
217 S=S*(N-R)/(R+1)*P/(1-P):R=R+1: GOTO 215
218 PRINT "P=";T: END
220 "NBINOM" INPUT "NEED?";R
221 INPUT "P?";P
222 N=R:E=P^R:L=0
223 L=L+E: WAIT 0: USING "##.#####": CLS
224 PRINT STR$ N;" =:";E;: CURSOR 24; PRINT "<=:";L;" >:";1-L;
225 CURSOR 16: INPUT "QUIT?";Q$: USING : WAIT : END
226 E=E*N/(N-R+1)*(1-P):N=N+1: GOTO 223
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)