def test_factorial(self, number, expected):
        '''Test our factorial function'''

        answer = factorial(number)
        assert answer == expected
示例#2
0
def rsum(n):
    t = factorial(
        4 * n) * (1103 + 26390 * n) / (factorial(n)**4 * 396**(4 * n))
    return t + rsum(n - 1) if n else t
示例#3
0
def sin_series_sum(x, n):
    """Uses Taylor's expansion to compute sin(x)
    """
    term = (-1)**n / factorial(2*n + 1) * x**(2*n+1)
    return term + sin_series_sum(x, n-1) if n else term
示例#4
0
def rsum(n):
    """ Caclulating pi using ramadans sum"""
    t = factorial(
        4 * n) * (1103 + 26390 * n) / (factorial(n)**4 * 396**(4 * n))
    return t + rsum(n - 1) if n else t
示例#5
0
def sin(x):
    y = (x / 180) * pi()
    result = y - ((y**3) / factorial(3)) + ((y**5) / factorial(5)) - (
        (y**7) / factorial(7))
    return result
示例#6
0
def my_sin(x, n):
    sine = 0
    for i in range(n):
        sine += ((-1)**i) * (x**(2. * i + 1)) / (factorial(2. * i + 1.))

    return sine