� ��g�Y���dZddlmZmZddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZmZdd lmZdd lmZmZmZdd lmZdd lmZdd lmZddlmZddgiZd�Zd�Z d�Z!d�Z"Gd�de��Z#Gd�de#��Z$dd�Z%dS)zFourier Series�)�oo�pi)�Wild)�Expr)�Add)�Tuple)�S)�Dummy�Symbol)�sympify)�sin�cos�sinc)� SeriesBase)� SeqFormula)�Interval)� is_sequence)�fourier_series� matplotlibc�V�ddlm}|d|d|dz }}td|ztz|z|z ��}d|z|||z|��z|z }|�|t j��dz }|td|z|||z|��z|z |dtf��fS)z,Returns the cos sequence in a Fourier seriesr�� integrate��) �sympy.integralsrrr�subsr �Zerorr) �func�limits�nr�x�L�cos_term�formula�a0s �d/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/series/fourier.py�fourier_cos_seqr's���)�)�)�)�)�)� �!�9�f�Q�i�&��)�+�q�A��1�Q�3�r�6�!�8�a�<� � �H��(�l�Y�Y�t�h���?�?�?�!�C�G� ���a��� � �1� $�B� �z�!�h�,���4�(�?�F�)K�)K�K��� !�1�b�z�+�+� +�+�c���ddlm}|d|d|dz }}td|ztz|z|z ��}t d|z|||z|��z|z |dt f��S)z,Returns the sin sequence in a Fourier seriesrrrr)rrr rrr)rrr rr!r"�sin_terms r&�fourier_sin_seqr+ s���)�)�)�)�)�)� �!�9�f�Q�i�&��)�+�q�A��1�Q�3�r�6�!�8�a�<� � �H� �a�(�l�Y�Y�t�h���%G�%G�G����q�"�:� '� '�'r(c���d�}d\}}}|�||��t t}}}t|t��r=t|��dkr|\}}}n#t|��dkr||��}|\}}t |t ��r|�|�t dt|��z���tj tj g}||vs||vrt d���t|||f��S)a Limits should be of the form (x, start, stop). x should be a symbol. Both start and stop should be bounded. Explanation =========== * If x is not given, x is determined from func. * If limits is None. Limit of the form (x, -pi, pi) is returned. Examples ======== >>> from sympy.series.fourier import _process_limits as pari >>> from sympy.abc import x >>> pari(x**2, (x, -2, 2)) (x, -2, 2) >>> pari(x**2, (-2, 2)) (x, -2, 2) >>> pari(x**2, None) (x, -pi, pi) c��|j}t|��dkr|���S|std��St d|z���)Nr�kz� specify dummy variables for %s. If the function contains more than one free symbol, a dummy variable should be supplied explicitly e.g. FourierSeries(m*n**2, (n, -pi, pi)))� free_symbols�len�popr � ValueError)r�frees r&�_find_xz _process_limits.<locals>._find_x@s]��� �� �t�9�9��>�>��8�8�:�:� �� ���:�:� ��P����� r()NNNN�rzInvalid limits given: %sz.Both the start and end value should be bounded) rrrr0� isinstancer r2�strr �NegativeInfinity�Infinityr )rrr4r!�start�stop� unboundeds r&�_process_limitsr=)s��. � � �&�N�A�u�d� �~� �������R�$�5���6�5�!�!�!� �v�;�;�!� � �#�N�A�u�d�d� ��[�[�A� � ���� � �A� �K�E�4� �a�� � �C�E�M�T�\��3�c�&�k�k�A�B�B�B��#�Q�Z�0�I� � ���T�Y�.�.��I�J�J�J� �A�u�d�#� $� $�$r(c��� ��d�}� �fd�}ddlm}m}m}||||������}|���} t dd�d�g���� t d �fd �g����| d D]B} | ���d } | D]#} || ���s|| �|��sd |fccS�$�Cd |fS)Nc��||jvS�N�r/)�exprsr!s r&�check_fxzfinite_check.<locals>.check_fxcs����*�*�*r(c���t|ttf��r7|jd}|��t |z z|z�z���dSdSdS)NrTF)r6r r�args�matchr)�_exprr!r"� sincos_args�a�bs ��r&� check_sincosz"finite_check.<locals>.check_sincosfs\��� �e�c�3�Z� (� (� ��*�Q�-�K�� � ��B�q�D��!��a��0�0�<��t��u�  � r(r)�TR2�TR1� sincos_to_sumrIc��|jSr@�� is_Integer�r.s r&�<lambda>zfinite_check.<locals>.<lambda>ss��� �r(c�"�|tjkSr@�r rrRs r&rSzfinite_check.<locals>.<lambda>ss ���Q�V� �r(�� propertiesrJc����|jvSr@rA�r.r!s �r&rSzfinite_check.<locals>.<lambda>ts������(?�r(rFT)�sympy.simplify.furLrMrN� as_coeff_addr� as_coeff_mul)�fr!r"rCrKrLrMrNrG� add_coeff�s� mul_coeffs�trIrJs ` @@r&� finite_checkrbas@�����+�+�+�������:�9�9�9�9�9�9�9�9�9� �M�#�#�c�c�!�f�f�+�+� &� &�E��"�"�$�$�I� �S�4�4�6K�6K�N�O�O�O�A� �S�?�?�?�?�B�C�C�C�A� �q�\� � ���^�^�%�%�a�(� �� � �A��H�Q��N�N� �l�l�1�a��&;�&;� ��a�x������� � ��;�r(c�X�eZdZdZd�Zed���Zed���Zed���Zed���Z ed���Z ed���Z ed ���Z ed ���Z ed ���Zed ���Zed ���Zd�Zdd�Zdd�Zd�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�ZdS)� FourierSeriesa9Represents Fourier sine/cosine series. Explanation =========== This class only represents a fourier series. No computation is performed. For how to compute Fourier series, see the :func:`fourier_series` docstring. See Also ======== sympy.series.fourier.fourier_series c�P�tt|��}tj|g|�R�Sr@)�mapr r�__new__)�clsrEs r&rgzFourierSeries.__new__�s)���7�D�!�!���|�C�'�$�'�'�'�'r(c��|jdS�Nr�rE��selfs r&�functionzFourierSeries.function�s���y��|�r(c�(�|jddS�Nrrrkrls r&r!zFourierSeries.x�����y��|�A��r(c�N�|jdd|jddfS)Nrrrkrls r&�periodzFourierSeries.period�s!��� �!� �Q����1��a��1�1r(c�(�|jddS)Nrrrkrls r&r%zFourierSeries.a0�rqr(c�(�|jddS)Nrrrkrls r&�anzFourierSeries.an�rqr(c�(�|jddS)Nrrkrls r&�bnzFourierSeries.bn�rqr(c�,�tdt��Srj)rrrls r&�intervalzFourierSeries.interval�s����2���r(c��|jjSr@)rz�infrls r&r:zFourierSeries.start�� ���}� � r(c��|jjSr@)rz�suprls r&r;zFourierSeries.stop�r}r(c��tSr@)rrls r&�lengthzFourierSeries.length�s��� r(c�X�t|jd|jdz ��dz S)Nrrr)�absrsrls r&r"zFourierSeries.L�s&���4�;�q�>�D�K��N�2�3�3�a�7�7r(c�B�|j}|�|��r|SdSr@)r!�has)rm�old�newr!s r&� _eval_subszFourierSeries._eval_subs�s*�� �F�� �7�7�1�:�:� ��K� � r(r5c��|�t|��Sg}|D]:}t|��|krn$|tjur|�|���;t |�S)a� Return the first n nonzero terms of the series. If ``n`` is None return an iterator. Parameters ========== n : int or None Amount of non-zero terms in approximation or None. Returns ======= Expr or iterator : Approximation of function expanded into Fourier series. Examples ======== >>> from sympy import fourier_series, pi >>> from sympy.abc import x >>> s = fourier_series(x, (x, -pi, pi)) >>> s.truncate(4) 2*sin(x) - sin(2*x) + 2*sin(3*x)/3 - sin(4*x)/2 See Also ======== sympy.series.fourier.FourierSeries.sigma_approximation )�iterr0r r�appendr)rmr �termsras r&�truncatezFourierSeries.truncate�sc��@ �9���:�:� ���� � �A��5�z�z�Q����������� � �Q������E�{�r(c�\���fd�t|d����D��}t|�S)a Return :math:`\sigma`-approximation of Fourier series with respect to order n. Explanation =========== Sigma approximation adjusts a Fourier summation to eliminate the Gibbs phenomenon which would otherwise occur at discontinuities. A sigma-approximated summation for a Fourier series of a T-periodical function can be written as .. math:: s(\theta) = \frac{1}{2} a_0 + \sum _{k=1}^{m-1} \operatorname{sinc} \Bigl( \frac{k}{m} \Bigr) \cdot \left[ a_k \cos \Bigl( \frac{2\pi k}{T} \theta \Bigr) + b_k \sin \Bigl( \frac{2\pi k}{T} \theta \Bigr) \right], where :math:`a_0, a_k, b_k, k=1,\ldots,{m-1}` are standard Fourier series coefficients and :math:`\operatorname{sinc} \Bigl( \frac{k}{m} \Bigr)` is a Lanczos :math:`\sigma` factor (expressed in terms of normalized :math:`\operatorname{sinc}` function). Parameters ========== n : int Highest order of the terms taken into account in approximation. Returns ======= Expr : Sigma approximation of function expanded into Fourier series. Examples ======== >>> from sympy import fourier_series, pi >>> from sympy.abc import x >>> s = fourier_series(x, (x, -pi, pi)) >>> s.sigma_approximation(4) 2*sin(x)*sinc(pi/4) - 2*sin(2*x)/pi + 2*sin(3*x)*sinc(3*pi/4)/3 See Also ======== sympy.series.fourier.FourierSeries.truncate Notes ===== The behaviour of :meth:`~sympy.series.fourier.FourierSeries.sigma_approximation` is different from :meth:`~sympy.series.fourier.FourierSeries.truncate` - it takes all nonzero terms of degree smaller than n, rather than first n nonzero ones. References ========== .. [1] https://en.wikipedia.org/wiki/Gibbs_phenomenon .. [2] https://en.wikipedia.org/wiki/Sigma_approximation c�l��g|]0\}}|tju�tt|z�z ��|z��1S�)r rrr)�.0�irar s �r&� <listcomp>z5FourierSeries.sigma_approximation.<locals>.<listcomp>3sD���%�%�%�$�!�Q��Q�V�O�O��b�1�f�q�j�!�!�A�%�#�O�Or(N)� enumerater)rmr r�s ` r&�sigma_approximationz!FourierSeries.sigma_approximation�sE���D%�%�%�%�)�D��!��H�2E�2E�%�%�%���E�{�r(c���t|��|j}}||jvrtd|�d|�����|j|z}|j|z}|�||jd||j|j f��S)a� Shift the function by a term independent of x. Explanation =========== f(x) -> f(x) + s This is fast, if Fourier series of f(x) is already computed. Examples ======== >>> from sympy import fourier_series, pi >>> from sympy.abc import x >>> s = fourier_series(x**2, (x, -pi, pi)) >>> s.shift(1).truncate() -4*cos(x) + cos(2*x) + 1 + pi**2/3 �'�' should be independent of r) r r!r/r2r%rnrrErvrx)rmr_r!r%�sfuncs r&�shiftzFourierSeries.shift7s{��*�q�z�z�4�6�1�� ��� � ��*�1�1�1�a�a�H�I�I� I� �W�q�[��� ��!���y�y��� �!� �r�4�7�D�G�.D�E�E�Er(c�r�t|��|j}}||jvrtd|�d|�����|j�|||z��}|j�|||z��}|j�|||z��}|�||j d|j ||f��S)a� Shift x by a term independent of x. Explanation =========== f(x) -> f(x + s) This is fast, if Fourier series of f(x) is already computed. Examples ======== >>> from sympy import fourier_series, pi >>> from sympy.abc import x >>> s = fourier_series(x**2, (x, -pi, pi)) >>> s.shiftx(1).truncate() -4*cos(x + 1) + cos(2*x + 2) + pi**2/3 r�r�r� r r!r/r2rvrrxrnrrEr%�rmr_r!rvrxr�s r&�shiftxzFourierSeries.shiftxV���*�q�z�z�4�6�1�� ��� � ��*�1�1�1�a�a�H�I�I� I� �W�\�\�!�Q��U� #� #�� �W�\�\�!�Q��U� #� #��� �"�"�1�a�!�e�,�,���y�y��� �!� �t�w��B�.?�@�@�@r(c�P�t|��|j}}||jvrtd|�d|�����|j�|��}|j�|��}|j|z}|jd|z}|� ||jd|||f��S)a� Scale the function by a term independent of x. Explanation =========== f(x) -> s * f(x) This is fast, if Fourier series of f(x) is already computed. Examples ======== >>> from sympy import fourier_series, pi >>> from sympy.abc import x >>> s = fourier_series(x**2, (x, -pi, pi)) >>> s.scale(2).truncate() -8*cos(x) + 2*cos(2*x) + 2*pi**2/3 r�r�rr) r r!r/r2rv� coeff_mulrxr%rEr)rmr_r!rvrxr%r�s r&�scalezFourierSeries.scalevs���*�q�z�z�4�6�1�� ��� � ��*�1�1�1�a�a�H�I�I� I� �W� � �q� !� !�� �W� � �q� !� !�� �W�q�[��� �!� �q� ���y�y��� �!� �r�2�r�l�;�;�;r(c�r�t|��|j}}||jvrtd|�d|�����|j�|||z��}|j�|||z��}|j�|||z��}|�||j d|j ||f��S)a� Scale x by a term independent of x. Explanation =========== f(x) -> f(s*x) This is fast, if Fourier series of f(x) is already computed. Examples ======== >>> from sympy import fourier_series, pi >>> from sympy.abc import x >>> s = fourier_series(x**2, (x, -pi, pi)) >>> s.scalex(2).truncate() -4*cos(2*x) + cos(4*x) + pi**2/3 r�r�rr�r�s r&�scalexzFourierSeries.scalex�r�r(Nrc�4�|D]}|tjur|cS�dSr@rU)rmr!�logx�cdirras r&�_eval_as_leading_termz#FourierSeries._eval_as_leading_term�s4��� � �A����������� � r(c��|dkr|jS|j�|��|j�|��zSrj)r%rv�coeffrx)rm�pts r&� _eval_termzFourierSeries._eval_term�s9�� ��7�7��7�N��w�}�}�R� � �4�7�=�=��#4�#4�4�4r(c�,�|�d��S)N�����)r�rls r&�__neg__zFourierSeries.__neg__�s���z�z�"�~�~�r(c��t|t��r�|j|jkrtd���|j|j}}|j|j�||��z}|j|jvr|S|j|jz}|j |j z}|j |j z}|� ||j d|||f��St||��S)N�(Both the series should have same periodsr)r6rdrsr2r!rnrr/rvrxr%rrEr)rm�otherr!�yrnrvrxr%s r&�__add__zFourierSeries.__add__�s��� �e�]� +� +� C��{�e�l�*�*� �!K�L�L�L��6�5�7�q�A��}�u�~�':�':�1�a�'@�'@�@�H��v�X�2�2�2�����5�8�#�B���5�8�#�B���5�8�#�B��9�9�X�t�y��|�b�"�b�\�B�B� B��4����r(c�.�|�| ��Sr@)r�)rmr�s r&�__sub__zFourierSeries.__sub__�s���|�|�U�F�#�#�#r()r5rj)�__name__� __module__� __qualname__�__doc__rg�propertyrnr!rsr%rvrxrzr:r;r�r"r�r�r�r�r�r�r�r�r�r�r�r�r�r(r&rdrds+�������� (�(�(�����X������X���2�2��X�2�����X������X������X������X���!�!��X�!��!�!��X�!�����X���8�8��X�8���� *�*�*�*�XD�D�D�D�LF�F�F�>A�A�A�@<�<�<�BA�A�A�@���� 5�5�5� ��� � � �&$�$�$�$�$r(rdc�b�eZdZdZd�Zed���Zed���Zd�Zd�Z d�Z d�Z d �Z d S) �FiniteFourierSeriesa�Represents Finite Fourier sine/cosine series. For how to compute Fourier series, see the :func:`fourier_series` docstring. Parameters ========== f : Expr Expression for finding fourier_series limits : ( x, start, stop) x is the independent variable for the expression f (start, stop) is the period of the fourier series exprs: (a0, an, bn) or Expr a0 is the constant term a0 of the fourier series an is a dictionary of coefficients of cos terms an[k] = coefficient of cos(pi*(k/L)*x) bn is a dictionary of coefficients of sin terms bn[k] = coefficient of sin(pi*(k/L)*x) or exprs can be an expression to be converted to fourier form Methods ======= This class is an extension of FourierSeries class. Please refer to sympy.series.fourier.FourierSeries for further information. See Also ======== sympy.series.fourier.FourierSeries sympy.series.fourier.fourier_series c �B���t|��}t|��}t|��}t|t��rt|��dk�s�|���\}}ddlm�|t�fd�|D���z}|�dddd������\}}|d�t|d|dz ��dz } td d �d �g� ��} td �fd�g� ��} i} i} |D]�}|� | t| t| z z�z��z��}|� | t| t| z z�z��z��}|r9|| | �|| t j��z| || <��|r9|| | �|| t j��z| || <��||z }��t|| | ��}t%j||||��S)Nr5r)�TR10c�&��g|] }�|����Sr�r�)r�r�r�s �r&r�z/FiniteFourierSeries.__new__.<locals>.<listcomp> s!���1�1�1�!�d�d�1�g�g�1�1�1r(F)�trig� power_base� power_exp�logrrrIc��|jSr@rPrRs r&rSz-FiniteFourierSeries.__new__.<locals>.<lambda>s��� �r(c��|tjuSr@rUrRs r&rSz-FiniteFourierSeries.__new__.<locals>.<lambda>s���QR�QW��r(rVrJc����|jvSr@rArYs �r&rSz-FiniteFourierSeries.__new__.<locals>.<lambda>s������0G�r()r r6rr0r[rZr�r�expandr�rrFrrr �getr rrrg)rhr]rrB�c�e�rexprr%�exp_lsr"rIrJrvrx�pra�qr�r!s @@r&rgzFiniteFourierSeries.__new__s+���� �A�J�J�������������5�%�(�(� &�S��Z�Z�1�_�_��%�%�'�'�D�A�q� .� .� .� .� .� .���1�1�1�1�q�1�1�1�2�2�E����5�U�e�Y^��_�_�l�l�n�n�J�B���q� �A��F�1�I��q� �)�*�*�Q�.�A��S�&<�&<�>W�>W�%Z�[�[�[�A��S�&G�&G�&G�&G�%J�K�K�K�A��B��B�� � ���G�G�A��A��a��L�1�$4� 5� 5�5�6�6���G�G�A��A��a��L�1�$4� 5� 5�5�6�6���� ��t�b�f�f�Q�q�T�1�6�&:�&:�:�B�q��t�H�H��� ��t�b�f�f�Q�q�T�1�6�&:�&:�:�B�q��t�H�H��!�G�B�B��"�b�"�%�%�E��|�C��F�E�2�2�2r(c ��|jrdnd}|tt|j������t|j���������dzz }td|��Srp)r%�max�setrv�keys�unionrxr)rm�_lengths r&rzzFiniteFourierSeries.interval&sk���w�%�!�!�A���3�s�4�7�<�<�>�>�*�*�0�0��T�W�\�\�^�^�1D�1D�E�E�F�F��J�J����7�#�#�#r(c� �|j|jz Sr@)r;r:rls r&r�zFiniteFourierSeries.length,s���y�4�:�%�%r(c�@�t|��|j}}||jvrtd|�d|�����|����|||z��}|j�|||z��}|�||jd|��S�Nr�r�r� r r!r/r2r�rrnrrE�rmr_r!rGr�s r&r�zFiniteFourierSeries.shiftx0����q�z�z�4�6�1�� ��� � ��*�1�1�1�a�a�H�I�I� I�� � ���$�$�Q��A��.�.��� �"�"�1�a�!�e�,�,���y�y��� �!� �e�4�4�4r(c���t|��|j}}||jvrtd|�d|�����|���|z}|j|z}|�||jd|��Sr�)r r!r/r2r�rnrrEr�s r&r�zFiniteFourierSeries.scale;su���q�z�z�4�6�1�� ��� � ��*�1�1�1�a�a�H�I�I� I�� � ���!�#��� ��!���y�y��� �!� �e�4�4�4r(c�@�t|��|j}}||jvrtd|�d|�����|����|||z��}|j�|||z��}|�||jd|��Sr�r�r�s r&r�zFiniteFourierSeries.scalexFr�r(c�V�|dkr|jS|j�|tj��t |t |jz z|jz��z|j �|tj��t|t |jz z|jz��zz}|Srj) r%rvr�r rrrr"r!rxr )rmr��_terms r&r�zFiniteFourierSeries._eval_termQs��� ��7�7��7�N��� � �B���'�'�#�b�B���K�.@�4�6�.I�*J�*J�J��'�+�+�b�!�&�)�)�C��b�4�6�k�0B�T�V�0K�,L�,L�L�M��� r(c��t|t��r5|�t|j|jdd�����St|t ��r||j|jkrtd���|j |j }}|j|j� ||��z}|j |j vr|St||jd���SdS)NrF)�finiter�)r) r6rdr�rrnrEr�rsr2r!rr/)rmr�r!r�rns r&r�zFiniteFourierSeries.__add__Ys��� �e�]� +� +� A��=�=��� �t�y��|�7<�">�">�">�?�?� ?� ��2� 3� 3� A��{�e�l�*�*� �!K�L�L�L��6�5�7�q�A��}�u�~�':�':�1�a�'@�'@�@�H��v�X�2�2�2���!�(�4�9�Q�<�@�@�@� @� A� Ar(N) r�r�r�r�rgr�rzr�r�r�r�r�r�r�r(r&r�r��s�������$�$�L"3�"3�"3�H�$�$��X�$� �&�&��X�&� 5� 5� 5� 5� 5� 5� 5� 5� 5����A�A�A�A�Ar(r�NTc��t|��}t||��}|d}||jvr|S|rHt|d|dz ��dz }t |||��\}}|rt |||��St d��}|d|dzdz }|jr�|�|| ��} || kr?t|||��\} } tddtf��} t||| | | f��S|| krHtj} tddtf��} t|||��} t||| | | f��St|||��\} } t|||��} t||| | | f��S)a`Computes the Fourier trigonometric series expansion. Explanation =========== Fourier trigonometric series of $f(x)$ over the interval $(a, b)$ is defined as: .. math:: \frac{a_0}{2} + \sum_{n=1}^{\infty} (a_n \cos(\frac{2n \pi x}{L}) + b_n \sin(\frac{2n \pi x}{L})) where the coefficients are: .. math:: L = b - a .. math:: a_0 = \frac{2}{L} \int_{a}^{b}{f(x) dx} .. math:: a_n = \frac{2}{L} \int_{a}^{b}{f(x) \cos(\frac{2n \pi x}{L}) dx} .. math:: b_n = \frac{2}{L} \int_{a}^{b}{f(x) \sin(\frac{2n \pi x}{L}) dx} The condition whether the function $f(x)$ given should be periodic or not is more than necessary, because it is sufficient to consider the series to be converging to $f(x)$ only in the given interval, not throughout the whole real line. This also brings a lot of ease for the computation because you do not have to make $f(x)$ artificially periodic by wrapping it with piecewise, modulo operations, but you can shape the function to look like the desired periodic function only in the interval $(a, b)$, and the computed series will automatically become the series of the periodic version of $f(x)$. This property is illustrated in the examples section below. Parameters ========== limits : (sym, start, end), optional *sym* denotes the symbol the series is computed with respect to. *start* and *end* denotes the start and the end of the interval where the fourier series converges to the given function. Default range is specified as $-\pi$ and $\pi$. Returns ======= FourierSeries A symbolic object representing the Fourier trigonometric series. Examples ======== Computing the Fourier series of $f(x) = x^2$: >>> from sympy import fourier_series, pi >>> from sympy.abc import x >>> f = x**2 >>> s = fourier_series(f, (x, -pi, pi)) >>> s1 = s.truncate(n=3) >>> s1 -4*cos(x) + cos(2*x) + pi**2/3 Shifting of the Fourier series: >>> s.shift(1).truncate() -4*cos(x) + cos(2*x) + 1 + pi**2/3 >>> s.shiftx(1).truncate() -4*cos(x + 1) + cos(2*x + 2) + pi**2/3 Scaling of the Fourier series: >>> s.scale(2).truncate() -8*cos(x) + 2*cos(2*x) + 2*pi**2/3 >>> s.scalex(2).truncate() -4*cos(2*x) + cos(4*x) + pi**2/3 Computing the Fourier series of $f(x) = x$: This illustrates how truncating to the higher order gives better convergence. .. plot:: :context: reset :format: doctest :include-source: True >>> from sympy import fourier_series, pi, plot >>> from sympy.abc import x >>> f = x >>> s = fourier_series(f, (x, -pi, pi)) >>> s1 = s.truncate(n = 3) >>> s2 = s.truncate(n = 5) >>> s3 = s.truncate(n = 7) >>> p = plot(f, s1, s2, s3, (x, -pi, pi), show=False, legend=True) >>> p[0].line_color = (0, 0, 0) >>> p[0].label = 'x' >>> p[1].line_color = (0.7, 0.7, 0.7) >>> p[1].label = 'n=3' >>> p[2].line_color = (0.5, 0.5, 0.5) >>> p[2].label = 'n=5' >>> p[3].line_color = (0.3, 0.3, 0.3) >>> p[3].label = 'n=7' >>> p.show() This illustrates how the series converges to different sawtooth waves if the different ranges are specified. .. plot:: :context: close-figs :format: doctest :include-source: True >>> s1 = fourier_series(x, (x, -1, 1)).truncate(10) >>> s2 = fourier_series(x, (x, -pi, pi)).truncate(10) >>> s3 = fourier_series(x, (x, 0, 1)).truncate(10) >>> p = plot(x, s1, s2, s3, (x, -5, 5), show=False, legend=True) >>> p[0].line_color = (0, 0, 0) >>> p[0].label = 'x' >>> p[1].line_color = (0.7, 0.7, 0.7) >>> p[1].label = '[-1, 1]' >>> p[2].line_color = (0.5, 0.5, 0.5) >>> p[2].label = '[-pi, pi]' >>> p[3].line_color = (0.3, 0.3, 0.3) >>> p[3].label = '[0, 1]' >>> p.show() Notes ===== Computing Fourier series can be slow due to the integration required in computing an, bn. It is faster to compute Fourier series of a function by using shifting and scaling on an already computed Fourier series rather than computing again. e.g. If the Fourier series of ``x**2`` is known the Fourier series of ``x**2 - 1`` can be found by shifting by ``-1``. See Also ======== sympy.series.fourier.FourierSeries References ========== .. [1] https://mathworld.wolfram.com/FourierSeries.html rrrr )r r=r/r�rbr�r �is_zerorr'rrrdr rr+) r]rr�r!r"� is_finite�res_fr �center�neg_fr%rvrxs r&rrjs���H �� � �A� �Q�� '� '�F��q� �A�������� �9� ��q� �F�1�I�%� &� &�� *��'��1�a�0�0�� �5� � 9�&�q�&�%�8�8� 8� �c� � �A��Q�i�&��)�#�q� (�F� �~� :����q�1�"� � �� ��:�:�$�Q���2�2�F�B���A��2�w�'�'�B� ��F�R��R�L�9�9� 9� �5�&�[�[���B��A��2�w�'�'�B� ��F�A�.�.�B� ��F�R��R�L�9�9� 9� �Q��� *� *�F�B�� ��F�A� &� &�B� ��F�R��R�L� 1� 1�1r()NT)&r��sympy.core.numbersrr�sympy.core.symbolr�sympy.core.exprr�sympy.core.addr�sympy.core.containersr�sympy.core.singletonr r r �sympy.core.sympifyr �(sympy.functions.elementary.trigonometricr rr�sympy.series.series_classr�sympy.series.sequencesr�sympy.sets.setsr�sympy.utilities.iterablesr�__doctest_requires__r'r+r=rbrdr�rr�r(r&�<module>r�s�����'�'�'�'�'�'�'�'�"�"�"�"�"�"� � � � � � �������'�'�'�'�'�'�"�"�"�"�"�"�+�+�+�+�+�+�+�+�&�&�&�&�&�&�C�C�C�C�C�C�C�C�C�C�0�0�0�0�0�0�-�-�-�-�-�-�$�$�$�$�$�$�1�1�1�1�1�1�,�l�^�<��+�+�+�'�'�'�5%�5%�5%�p���<Y$�Y$�Y$�Y$�Y$�J�Y$�Y$�Y$�x LA�LA�LA�LA�LA�-�LA�LA�LA�^A2�A2�A2�A2�A2�A2r(
Memory