I am relatively new to QBasic and am writing a simple tool which will compute (and display) the results of the Binomial PDF and CDF given n trials, k opportunities, and a probability of success in each trial of ReplyProb.
I need to use a Factorial function but since QBasic has no such function I attempted to write a subroutine to do my own and am still getting an "Operator Overload" message.
Any help would be most appreciated
What the code is supposed to do:
------------------------------------------------------------
Print out the PDF and CDF of the discrete Binomial distribution for K successes out of N trials with the probability of success of each trial = ReplyProb
The code is as follows:
----------------------------------------------------------------------------------------------------------------------
DECLARE SUB simpfact (in AS INTEGER)
DIM SHARED N AS INTEGER
DIM SHARED K AS INTEGER
DIM SHARED i AS INTEGER
PRINT ("Input Reply Probability"
INPUT ReplyProb
PRINT ("Input Reply Threshold"
INPUT K
PRINT ("Input Sliding Window Length"
INPUT N
CALL simpfact(N)
a = total
FOR i = K TO N
CALL simpfact(i)
b(i) = total
CALL simpfact(N - i)
c(i) = total
BinomialSum = a / (b(i) * c(i)) * ReplyProb ^ i * ReplyProb ^ (N - i)
tot(i) = tot(i) + BinomialSum
PRINT ("Binomial Sum Iterator" BinomialSum
PRINT ("Cumulative Binomial Sum=" tot(i)
PRINT (""
NEXT i
END
------------------------------------------------------------
------------------------------------------------------------
What the subroutine should do:
------------------------------------------------------------
(1) Call the subroutine simpfact with parameter N
(2) Since in is not equal to 1 (say, N=9), b=in=9, total = total * b = 9; if N = in = 1, then total=1 and the value returned to total after the function call is 1
(3) compute b as (9-1), (9-2), ... , (9-9) and total = total * 9 * (9-1) * (9-2) * ...
(4) return the value of total to the line immediately after the function call
------------------------------------------------------------
The subroutine is as follows:
------------------------------------------------------------------------------------------------------------------------
SUB simpfact (in AS INTEGER) STATIC
total=1
FOR i = 0 TO in
IF (in = 1) THEN
total = 1
ELSE
b = (in - i)
total = total * b
END IF
NEXT i
END SUB
------------------------------------------------------------
I need to use a Factorial function but since QBasic has no such function I attempted to write a subroutine to do my own and am still getting an "Operator Overload" message.
Any help would be most appreciated
What the code is supposed to do:
------------------------------------------------------------
Print out the PDF and CDF of the discrete Binomial distribution for K successes out of N trials with the probability of success of each trial = ReplyProb
The code is as follows:
----------------------------------------------------------------------------------------------------------------------
DECLARE SUB simpfact (in AS INTEGER)
DIM SHARED N AS INTEGER
DIM SHARED K AS INTEGER
DIM SHARED i AS INTEGER
PRINT ("Input Reply Probability"
INPUT ReplyProb
PRINT ("Input Reply Threshold"
INPUT K
PRINT ("Input Sliding Window Length"
INPUT N
CALL simpfact(N)
a = total
FOR i = K TO N
CALL simpfact(i)
b(i) = total
CALL simpfact(N - i)
c(i) = total
BinomialSum = a / (b(i) * c(i)) * ReplyProb ^ i * ReplyProb ^ (N - i)
tot(i) = tot(i) + BinomialSum
PRINT ("Binomial Sum Iterator" BinomialSum
PRINT ("Cumulative Binomial Sum=" tot(i)
PRINT (""
NEXT i
END
------------------------------------------------------------
------------------------------------------------------------
What the subroutine should do:
------------------------------------------------------------
(1) Call the subroutine simpfact with parameter N
(2) Since in is not equal to 1 (say, N=9), b=in=9, total = total * b = 9; if N = in = 1, then total=1 and the value returned to total after the function call is 1
(3) compute b as (9-1), (9-2), ... , (9-9) and total = total * 9 * (9-1) * (9-2) * ...
(4) return the value of total to the line immediately after the function call
------------------------------------------------------------
The subroutine is as follows:
------------------------------------------------------------------------------------------------------------------------
SUB simpfact (in AS INTEGER) STATIC
total=1
FOR i = 0 TO in
IF (in = 1) THEN
total = 1
ELSE
b = (in - i)
total = total * b
END IF
NEXT i
END SUB
------------------------------------------------------------