�
��gl
� �n � d Z ddlmZ ddlmZmZmZ ddlmZ ddl m
Z
ddlmZ ddl
mZ ddlmZ dd
�ZdS )
zX
This module implements a method to find
Euler-Lagrange Equations for given Lagrangian.
� )�combinations_with_replacement)�
Derivative�Function�diff)�Eq)�S)�Symbol��sympify)�iterable� c �� �� t �� � rt �� � n�f��s(t | � t � � � � �n,�D ])}t |t � � st d|z � � ��*t |� � rt |� � n|f}|s�d j }nt d� |D � � � � }t d� |D � � � � st d|z � � ��D ]"}||j k st d|�d|��� � ��#t �fd�| � t � � D � � dgz � � }g }�D ]�}t | |� � }t d |d z � � D ]A}t ||� � D ].}|t j |z t | t |g|�R � g|�R � z z }�/�Bt! |d� � } t | t � � r|� | � � ��|S )
a5
Find the Euler-Lagrange equations [1]_ for a given Lagrangian.
Parameters
==========
L : Expr
The Lagrangian that should be a function of the functions listed
in the second argument and their derivatives.
For example, in the case of two functions $f(x,y)$, $g(x,y)$ and
two independent variables $x$, $y$ the Lagrangian has the form:
.. math:: L\left(f(x,y),g(x,y),\frac{\partial f(x,y)}{\partial x},
\frac{\partial f(x,y)}{\partial y},
\frac{\partial g(x,y)}{\partial x},
\frac{\partial g(x,y)}{\partial y},x,y\right)
In many cases it is not necessary to provide anything, except the
Lagrangian, it will be auto-detected (and an error raised if this
cannot be done).
funcs : Function or an iterable of Functions
The functions that the Lagrangian depends on. The Euler equations
are differential equations for each of these functions.
vars : Symbol or an iterable of Symbols
The Symbols that are the independent variables of the functions.
Returns
=======
eqns : list of Eq
The list of differential equations, one for each function.
Examples
========
>>> from sympy import euler_equations, Symbol, Function
>>> x = Function('x')
>>> t = Symbol('t')
>>> L = (x(t).diff(t))**2/2 - x(t)**2/2
>>> euler_equations(L, x(t), t)
[Eq(-x(t) - Derivative(x(t), (t, 2)), 0)]
>>> u = Function('u')
>>> x = Symbol('x')
>>> L = (u(t, x).diff(t))**2/2 - (u(t, x).diff(x))**2/2
>>> euler_equations(L, u(t, x), [t, x])
[Eq(-Derivative(u(t, x), (t, 2)) + Derivative(u(t, x), (x, 2)), 0)]
References
==========
.. [1] https://en.wikipedia.org/wiki/Euler%E2%80%93Lagrange_equation
zFunction expected, got: %sr c 3 �4 K � | ]}t |� � V � �d S �Nr
)�.0�vars �d/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/calculus/euler.py� <genexpr>z"euler_equations.<locals>.<genexpr>V s( � � � �2�2�c�W�S�\�\�2�2�2�2�2�2� c 3 �@ K � | ]}t |t � � V � �d S r )�
isinstancer )r �vs r r z"euler_equations.<locals>.<genexpr>X s, � � � �3�3��z�!�V�$�$�3�3�3�3�3�3r z!Variables are not symbols, got %sz
Variables z do not match args: c �J �� g | ]}|j �v �t |j � � �� S r
)�expr�len� variables)r �d�funcss �r �
<listcomp>z#euler_equations.<locals>.<listcomp>_ s5 �� � ,� ,� ,�a��6�U�?�?� �Q�[�!�!�*�?�?r � )r �tuple�atomsr r � TypeError�args�all�
ValueError�maxr r �ranger r �NegativeOner �append)
�Lr �vars�f�order�eqns�eq�i�p�new_eqs
` r �euler_equationsr4 s_ �� �t %�U�O�O�9�E�%�L�L�L�%��E�� B��a�g�g�h�'�'�(�(���� B� B�A��a��*�*�
B�� <�q� @�A�A�A�
B� #�4�.�.�5�5��;�;�;�t�g�D�� 3��Q�x�}����2�2�T�2�2�2�2�2���3�3�d�3�3�3�3�3� D��;�d�B�C�C�C�
� O� O���q�v�~�~��*�T�T�T�1�1�M�N�N�N� �
� ,� ,� ,� ,�1�7�7�:�+>�+>� ,� ,� ,�/0�c�2�
3�
3�E� �D�
� � ��
�!�Q�Z�Z���q�%�!�)�$�$� D� D�A�2�4��;�;�
D�
D���!�-��*�4��4��;�A�;�;�;�+C��+C�+C�+C�C�C���
D��B������f�b�!�!� ��K�K�������Kr N)r
r
)�__doc__� itertoolsr �sympy.core.functionr r r �sympy.core.relationalr �sympy.core.singletonr �sympy.core.symbolr �sympy.core.sympifyr �sympy.utilities.iterablesr r4 r
r r �<module>r= s� ��� � 4� 3� 3� 3� 3� 3� <� <� <� <� <� <� <� <� <� <� $� $� $� $� $� $� "� "� "� "� "� "� $� $� $� $� $� $� &� &� &� &� &� &� .� .� .� .� .� .�^� ^� ^� ^� ^� ^r