mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 14:35:23 +01:00
Merge pull request #320 from Vhizux/feature/binomial-distribution
binomial distribution
This commit is contained in:
@@ -113,3 +113,4 @@ from .combine_like_terms import *
|
|||||||
from .signum_function import *
|
from .signum_function import *
|
||||||
from .conditional_probability import *
|
from .conditional_probability import *
|
||||||
from .arc_length import *
|
from .arc_length import *
|
||||||
|
from .binomial_distribution import *
|
||||||
|
|||||||
42
mathgenerator/funcs/binomial_distribution.py
Normal file
42
mathgenerator/funcs/binomial_distribution.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
from .__init__ import *
|
||||||
|
|
||||||
|
|
||||||
|
def factorial(n):
|
||||||
|
|
||||||
|
if n == 1 or n == 0:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return n * factorial(n - 1)
|
||||||
|
|
||||||
|
|
||||||
|
def newton_symbol(n, k):
|
||||||
|
return factorial(n) / (factorial(k) * factorial(n - k))
|
||||||
|
|
||||||
|
|
||||||
|
def binomialDistFunc():
|
||||||
|
|
||||||
|
rejected_fraction = float(random.randint(30, 40)) + random.random()
|
||||||
|
batch = random.randint(10, 20)
|
||||||
|
rejections = random.randint(1, 9)
|
||||||
|
|
||||||
|
answer = 0
|
||||||
|
|
||||||
|
rejected_fraction = round(rejected_fraction, 2)
|
||||||
|
|
||||||
|
problem = "A manufacturer of metal pistons finds that, on average, {0:}% "\
|
||||||
|
"of the pistons they manufacture are rejected because " \
|
||||||
|
"they are incorrectly sized. What is the probability that a "\
|
||||||
|
"batch of {1:} pistons will contain no more than {2:} " \
|
||||||
|
"rejected pistons?".format(rejected_fraction, batch, rejections)
|
||||||
|
|
||||||
|
for i in range(0, rejections + 1):
|
||||||
|
answer += newton_symbol(float(batch), float(i)) * ((rejected_fraction / 100.) ** float(i)) * \
|
||||||
|
((1 - (rejected_fraction / 100.)) ** (float(batch) - float(i)))
|
||||||
|
|
||||||
|
answer = round(100 * answer, 2)
|
||||||
|
|
||||||
|
return problem, answer
|
||||||
|
|
||||||
|
|
||||||
|
binomial_distribution = Generator("Binomial distribution", 107,
|
||||||
|
"P(X<x)=", "c", binomialDistFunc)
|
||||||
Reference in New Issue
Block a user