K il ldZddlmZddlmZmZmZddlmZddl m Z ddl m Z ddl mZddlmZd d Zy ) zX This module implements a method to find Euler-Lagrange Equations for given Lagrangian. )combinations_with_replacement) DerivativeFunctiondiff)Eq)S)Symbolsympify)iterablec t|r t|n|f}|st|jt}n%|D] }t |trt d|zt|r t|n|f}|s|dj }ntd|D}td|Dst d|z|D]"}||j k(rtd|d|t|jtDcgc]%}|j|vrt|j'c}dgz}g}|D]}t||}td|dzD]A}t!||D]0} |t"j$|zt|t|g| g| zz}2Ct'|d} t | t&s|j)| |Scc}w) 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: %src32K|]}t|ywNr ).0vars Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/calculus/euler.py z"euler_equations..Vs2cWS\2sc3<K|]}t|tywr) isinstancer )rvs rrz"euler_equations..Xs3z!V$3sz!Variables are not symbols, got %sz Variables z do not match args: )r tupleatomsrr TypeErrorargsall ValueErrormaxrexprlen variablesrrangerr NegativeOnerappend) Lfuncsvarsfdordereqnseqipnew_eqs reuler_equationsr0st%UOE%L%E aggh'( BAa* ,a66U?Q[[!,/0c2 3E D   !QZq%!)$ DA24; D!--*44;A;+C+CCC D DB fb ! KK   K,s*G N)r1)__doc__ itertoolsrsympy.core.functionrrrsympy.core.relationalrsympy.core.singletonrsympy.core.symbolr sympy.core.sympifyr sympy.utilities.iterablesr r0r1rr;s*4<<$"$&.^r: