Example #1
0
def bernoulli_number(m):
    if m > 2 and m % 2 == 1:
        return Rational(0)
    out = 0
    for k in range(m + 1):
        for v in range(k + 1):

            c = choose(k, v)
            R = Rational(v**m, k + 1)
            out += R * c * (-1)**v
    return out
Example #2
0
def bernstein_polynomial(v,n):
    """Bernstein Basis Polynomial"""
    B = Polynomial([1,-1])
    X = Polynomial([1])
    bi = choose(n,v)
    return X**v * B**(n-v) * bi
Example #3
0
def binomial_eq(n, p, k):
    return choose(n, k) * p**k * (1 - p)**(n - k)
Example #4
0
from Rationals import bernoulli_number, Rational
from Polynomials import Polynomial
from Combinatorics import choose

for n in range(1, 9):
    P = Polynomial([0])
    for k in range(n + 1):
        b = bernoulli_number(n - k)
        c = choose(n, k)
        co = b * c
        P += Polynomial([0] * k + [co])

    print(P)
    print()
Example #5
0
def neg_binomial_eq(r, p, k):
    return choose(k + r - 1, k) * (1 - p)**r * p**k