def fourier_series ( x , f , n = 0 ) : # Make the parameter objects for all the terms a0 ,  * cos_a = parameters ( ',' . join ( [ 'a{}' . format ( i ) for i in range ( 0 , n + 1 ) ] ) ) sin_b = parameters ( ',' . join ( [ 'b{}' . format ( i ) for i in range ( 1 , n + 1 ) ] ) ) # Construct the series series = a0 + sum ( ai * cos ( i * f * x ) + bi * sin ( i * f * x ) for i , ( ai , bi ) in enumerate ( zip ( cos_a , sin_b ) , start = 1 ) ) return series
fourier series with python
Returns a symbolic fourier series of order n .
def fourier_series(x, f, n=0):
    """
    Returns a symbolic fourier series of order `n`.

    :param n: Order of the fourier series.
    :param x: Independent variable
    :param f: Frequency of the fourier series
    """
    # Make the parameter objects for all the terms
    a0, *cos_a = parameters(','.join(['a{}'.format(i) for i in range(0, n + 1)]))
    sin_b = parameters(','.join(['b{}'.format(i) for i in range(1, n + 1)]))
    # Construct the series
    series = a0 + sum(ai * cos(i * f * x) + bi * sin(i * f * x)
                     for i, (ai, bi) in enumerate(zip(cos_a, sin_b), start=1))
    return series