sourcecode_fs.py
def fourierMain(function, nMax, showPrevTerm):
    """
        Main function for calling produceFourierSeries and plotting

        ----------

        Parameters

        ----------

        function: string
            function key

        nMax: int
            number of terms
        
        showPrevTerm: bool
            true if most recent term should be displayed. False otherwise
    """

    # window upper and lower
#     xMin = -np.pi
#     xMax = np.pi

    functions = {'Linear':[f1, -np.pi, np.pi],'Square Wave':[f2, -np.pi/2, np.pi/2],'Cubic':[f3, -np.pi, np.pi],\
                '4B':[example_4b,-np.pi,np.pi],'4C':[example_4c,-np.pi,np.pi],\
                '5A_Sine':[example_5a_sine,-1.,1.],'5A_Cosine':[example_5a_cosine,-1.,1.],
                '5B_Sine':[example_5b_sine,-1.,1.],'5B_Cosine':[example_5b_cosine,-2.,2.]}
 
    f, xMin, xMax = functions[function]
    x = np.arange(xMin, xMax, 0.001)
    fx = f(x,xMin,xMax)
    fMin = np.min(fx)
    fMax = np.max(fx)

    _, ax = plt.subplots(figsize=(16,10))

    seriesApprox, prev = produceFourierSeries(x, nMax, xMin, xMax, f)

    if nMax > 0:
        label_tmp = 'Partial Sums, N={}'
    else:
        label_tmp = 'a0'
    
    ax.plot(x, seriesApprox, label=label_tmp.format(nMax), color='C0')
    # plot prev term if necessary. Don't plot if no prev term. (Shouldnt be possible with slider lim anyway)
    if (nMax > 0) and showPrevTerm: ax.plot(x, prev, label='Latest Term', color='g')
    ax.plot(x, fx, label='Function over Fundamental Range', color='C1')

    xbuffer = np.abs(xMax-xMin)/5.
    ybuffer = np.abs(fMax-fMin)/5.
    
    ax.set_xlabel('x')
    ax.set_ylabel('f(x)')
    ax.set_xlim(xMin-xbuffer,xMax+xbuffer)
    ax.set_ylim(fMin-ybuffer,fMax+ybuffer)
    ax.axhline(0,ls='-',c='k',lw=0.5)
    ax.axvline(0,ls='-',c='k',lw=0.5)
    ax.legend()
    plt.show()

        Main function for calling produceFourierSeries and plotting

        ----------

        Parameters

        ----------

        function: string
            function key

        nMax: int
            number of terms
        
        showPrevTerm: bool
            true if most recent term should be displayed. False otherwise
    
Main function for calling produceFourierSeries and plotting
Parameters



string
function key

int
number of terms

bool
true if most recent term should be displayed. False otherwise
Main function for calling produceFourierSeries and plotting Parameters string function key int number of terms bool true if most recent term should be displayed . False otherwise
def fourierMain(function, nMax, showPrevTerm):
    functions = {'Linear':[f1, -np.pi, np.pi],'Square Wave':[f2, -np.pi/2, np.pi/2],'Cubic':[f3, -np.pi, np.pi],\
                '4B':[example_4b,-np.pi,np.pi],'4C':[example_4c,-np.pi,np.pi],\
                '5A_Sine':[example_5a_sine,-1.,1.],'5A_Cosine':[example_5a_cosine,-1.,1.],
                '5B_Sine':[example_5b_sine,-1.,1.],'5B_Cosine':[example_5b_cosine,-2.,2.]}
    f, xMin, xMax = functions[function]
    x = np.arange(xMin, xMax, 0.001)
    fx = f(x,xMin,xMax)
    fMin = np.min(fx)
    fMax = np.max(fx)
    _, ax = plt.subplots(figsize=(16,10))
    seriesApprox, prev = produceFourierSeries(x, nMax, xMin, xMax, f)
    if nMax > 0:
        label_tmp = 'Partial Sums, N={}'
    else:
        label_tmp = 'a0'
    ax.plot(x, seriesApprox, label=label_tmp.format(nMax), color='C0')
    if (nMax > 0) and showPrevTerm: ax.plot(x, prev, label='Latest Term', color='g')
    ax.plot(x, fx, label='Function over Fundamental Range', color='C1')
    xbuffer = np.abs(xMax-xMin)/5.
    ybuffer = np.abs(fMax-fMin)/5.
    ax.set_xlabel('x')
    ax.set_ylabel('f(x)')
    ax.set_xlim(xMin-xbuffer,xMax+xbuffer)
    ax.set_ylim(fMin-ybuffer,fMax+ybuffer)
    ax.axhline(0,ls='-',c='k',lw=0.5)
    ax.axvline(0,ls='-',c='k',lw=0.5)
    ax.legend()
    plt.show()
def fourierMain ( function , nMax , showPrevTerm ) : functions = { 'Linear' : [ f1 , - np . pi , np . pi ] , 'Square Wave' : [ f2 , - np . pi / 2 , np . pi / 2 ] , 'Cubic' : [ f3 , - np . pi , np . pi ] , '4B' : [ example_4b , - np . pi , np . pi ] , '4C' : [ example_4c , - np . pi , np . pi ] , '5A_Sine' : [ example_5a_sine , - 1. , 1. ] , '5A_Cosine' : [ example_5a_cosine , - 1. , 1. ] , '5B_Sine' : [ example_5b_sine , - 1. , 1. ] , '5B_Cosine' : [ example_5b_cosine , - 2. , 2. ] } f , xMin , xMax = functions [ function ] x = np . arange ( xMin , xMax , 0.001 ) fx = f ( x , xMin , xMax ) fMin = np . min ( fx ) fMax = np . max ( fx ) _ , ax = plt . subplots ( figsize = ( 16 , 10 ) ) seriesApprox , prev = produceFourierSeries ( x , nMax , xMin , xMax , f ) if nMax > 0 : label_tmp = 'Partial Sums, N={}' else : label_tmp = 'a0' ax . plot ( x , seriesApprox , label = label_tmp . format ( nMax ) , color = 'C0' ) if ( nMax > 0 ) and showPrevTerm : ax . plot ( x , prev , label = 'Latest Term' , color = 'g' ) ax . plot ( x , fx , label = 'Function over Fundamental Range' , color = 'C1' ) xbuffer = np . abs ( xMax - xMin ) / 5. ybuffer = np . abs ( fMax - fMin ) / 5. ax . set_xlabel ( 'x' ) ax . set_ylabel ( 'f(x)' ) ax . set_xlim ( xMin - xbuffer , xMax + xbuffer ) ax . set_ylim ( fMin - ybuffer , fMax + ybuffer ) ax . axhline ( 0 , ls = '-' , c = 'k' , lw = 0.5 ) ax . axvline ( 0 , ls = '-' , c = 'k' , lw = 0.5 ) ax . legend ( ) plt . show ( )
Main function for calling produceFourierSeries and plotting
Parameters
Main function for calling produceFourierSeries and plotting Parameters
"""
        Main function for calling produceFourierSeries and plotting

        ----------

        Parameters

        ----------

        function: string
            function key

        nMax: int
            number of terms
        
        showPrevTerm: bool
            true if most recent term should be displayed. False otherwise
    """ # window upper and lower #     xMin = -np.pi #     xMax = np.pi # plot prev term if necessary. Don't plot if no prev term. (Shouldnt be possible with slider lim anyway)
function
nMax
showPrevTerm