� ��g�v����ddlZddlmZddlmZddlmZddlmZddl m Z m Z ddl m Z ddlmZdd lmZd d lmZd d lmZmZd d lmZd dlmZmZd dlmZmZddgiZd�Z Gd�de��Z!d�Z"Gd�de!e��Z#e#xZ$Z%e&fd�Z'e&fd�Z(d7d�Z)d�Z*d�Z+d�Z,d�Z-d �Z.d!�Z/e d"�#��d$���Z0d8d&�Z1d'�Z2d%d(d)�d*�Z3d9d+�Z4d:d-�Z5d.�Z6d/�Z7d0�Z8 d;d3�Z9d<d5�Z:d6�Z;dS)=�N)�Basic)�S)�Symbol��sympify)�cos�sin)�doctest_depends_on)�sympy_deprecation_warning)� is_sequence�)� ShapeError)� _cholesky�_LDLdecomposition)� MatrixBase)�MutableRepMatrix� RepMatrix)�_lower_triangular_solve�_upper_triangular_solve)�symarray�numpyc��|jS)zReturns True if x is zero.)�is_zero)�xs �d/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/matrices/dense.py�_iszerors �� �9��c���eZdZdZdZdZdZed���Zd�Z d�Z d�Z dd �Z dd �Z d �Zd �Zeje _eje _eje_eje_dS)� DenseMatrixzJMatrix implementation based on DomainMatrix as the internal representationFg��Q�$@�c�N�tddd���|���S)Nzy The private _mat attribute of Matrix is deprecated. Use the .flat() method instead. z1.9z$deprecated-private-matrix-attributes)�deprecated_since_version�active_deprecations_target)r �flat��selfs r�_matzDenseMatrix._mat)s6��!� �&+�'M�  � � � ��y�y�{�{�rc ��|�|�dd��|�dt��|�dd�����S)N�method�GE� iszerofunc�try_block_diagF)r)r+r,)�inv�getr)r&�kwargss r� _eval_inversezDenseMatrix._eval_inverse6sS���x�x�v�z�z�(�D�9�9�#)�:�:�l�G�#D�#D�'-�z�z�2B�E�'J�'J��L�L� Lrc�f�ddlm}|�|j�����S)z4Returns an Immutable version of this Matrix r )�ImmutableDenseMatrix)� immutabler2�_fromrep�_rep�copy)r&�clss r� as_immutablezDenseMatrix.as_immutable;s4�� ;�:�:�:�:�:��|�|�D�I�N�N�,�,�-�-�-rc� �t|��S)aBReturns a mutable version of this matrix Examples ======== >>> from sympy import ImmutableMatrix >>> X = ImmutableMatrix([[1, 2], [3, 4]]) >>> Y = X.as_mutable() >>> Y[1, 1] = 5 # Can set values in Y >>> Y Matrix([ [1, 2], [3, 5]]) )�Matrixr%s r� as_mutablezDenseMatrix.as_mutableAs���d�|�|�rTc�$�t||���S�N)� hermitian)r�r&r>s r�choleskyzDenseMatrix.choleskyRs�����3�3�3�3rc�$�t||���Sr=)rr?s r�LDLdecompositionzDenseMatrix.LDLdecompositionUs�� ���;�;�;�;rc�"�t||��S�N)r�r&�rhss r�lower_triangular_solvez"DenseMatrix.lower_triangular_solveX���&�t�S�1�1�1rc�"�t||��SrD)rrEs r�upper_triangular_solvez"DenseMatrix.upper_triangular_solve[rHrN�T)�__name__� __module__� __qualname__�__doc__� is_MatrixExpr� _op_priority�_class_priority�propertyr'r0r8r;r@rBrGrJrrrr�rrrrs�������T�T��M��L��O� � � ��X� �L�L�L� .�.�.� ���"4�4�4�4�<�<�<�<�2�2�2�2�2�2�&/�%6�H��%6�%>���%<�%D��"�%<�%D��"�"�"rrc�2�t|dd��r|���St|t��r|St |d��rJ|���}t |j��dkrt|��St|��S|S)z0Return a matrix as a Matrix, otherwise return x.� is_MatrixF� __array__r) �getattrr;� isinstancer�hasattrrW�len�shaperr:)r�as r�_force_mutabler^ds����q�+�u�%�%���|�|�~�~�� �A�u� � ���� ��K� � �� �K�K�M�M�� �q�w�<�<�1� � ��1�:�:� ��a�y�y�� �Hrc��eZdZd�ZdS)�MutableDenseMatrixc ��ddlm}|������D]\\}}}||fi|��|||f<�dS)z�Applies simplify to the elements of a matrix in place. This is a shortcut for M.applyfunc(lambda x: simplify(x, ratio, measure)) See Also ======== sympy.simplify.simplify.simplify r)�simplifyN)�sympy.simplify.simplifyrb�todok�items)r&r/� _simplify�i�j�elements rrbzMutableDenseMatrix.simplifytsm�� B�A�A�A�A�A�#�z�z�|�|�1�1�3�3� 6� 6�O�F�Q��G�"��7�5�5�f�5�5�D��A��J�J� 6� 6rN)rLrMrNrbrTrrr`r`rs#������ 6� 6� 6� 6� 6rr`c�x�ddlm}|t|��|��}t|��D] \}}|||<� |S)zmConverts Python list of SymPy expressions to a NumPy array. See Also ======== matrix2numpy r��empty)rrlr[� enumerate)�l�dtyperlr]rg�ss r� list2numpyrq�sV�������� ��c�!�f�f�e���A��!� � �����1���!��� �Hrc��ddlm}||j|��}t|j��D](}t|j��D]}|||f|||f<��)|S)zYConverts SymPy's matrix to a NumPy array. See Also ======== list2numpy rrk)rrlr\�range�rows�cols)�mrorlr]rgrhs r� matrix2numpyrw�sx�������� ��a�g�u���A� �1�6�]�]�����q�v��� � �A���1��g�A�a��d�G�G� � �Hr�c�(�t|t��r|dkr"td�|�����||kr#td�||�����||fD]M}t|t��r|dks ||dz kr'td�|dz ||������Nt |��}t |��}t |��}t|��}||||f<||||f<||||f<| |||f<|S)a� Returns a a Givens rotation matrix, a a rotation in the plane spanned by two coordinates axes. Explanation =========== The Givens rotation corresponds to a generalization of rotation matrices to any number of dimensions, given by: .. math:: G(i, j, \theta) = \begin{bmatrix} 1 & \cdots & 0 & \cdots & 0 & \cdots & 0 \\ \vdots & \ddots & \vdots & & \vdots & & \vdots \\ 0 & \cdots & c & \cdots & -s & \cdots & 0 \\ \vdots & & \vdots & \ddots & \vdots & & \vdots \\ 0 & \cdots & s & \cdots & c & \cdots & 0 \\ \vdots & & \vdots & & \vdots & \ddots & \vdots \\ 0 & \cdots & 0 & \cdots & 0 & \cdots & 1 \end{bmatrix} Where $c = \cos(\theta)$ and $s = \sin(\theta)$ appear at the intersections ``i``\th and ``j``\th rows and columns. For fixed ``i > j``\, the non-zero elements of a Givens matrix are given by: - $g_{kk} = 1$ for $k \ne i,\,j$ - $g_{kk} = c$ for $k = i,\,j$ - $g_{ji} = -g_{ij} = -s$ Parameters ========== i : int between ``0`` and ``dim - 1`` Represents first axis j : int between ``0`` and ``dim - 1`` Represents second axis dim : int bigger than 1 Number of dimentions. Defaults to 3. Examples ======== >>> from sympy import pi, rot_givens A counterclockwise rotation of pi/3 (60 degrees) around the third axis (z-axis): >>> rot_givens(1, 0, pi/3) Matrix([ [ 1/2, -sqrt(3)/2, 0], [sqrt(3)/2, 1/2, 0], [ 0, 0, 1]]) If we rotate by pi/2 (90 degrees): >>> rot_givens(1, 0, pi/2) Matrix([ [0, -1, 0], [1, 0, 0], [0, 0, 1]]) This can be generalized to any number of dimensions: >>> rot_givens(1, 0, pi/2, dim=4) Matrix([ [0, -1, 0, 0], [1, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) References ========== .. [1] https://en.wikipedia.org/wiki/Givens_rotation See Also ======== rot_axis1: Returns a rotation matrix for a rotation of theta (in radians) about the 1-axis (clockwise around the x axis) rot_axis2: Returns a rotation matrix for a rotation of theta (in radians) about the 2-axis (clockwise around the y axis) rot_axis3: Returns a rotation matrix for a rotation of theta (in radians) about the 3-axis (clockwise around the z axis) rot_ccw_axis1: Returns a rotation matrix for a rotation of theta (in radians) about the 1-axis (counterclockwise around the x axis) rot_ccw_axis2: Returns a rotation matrix for a rotation of theta (in radians) about the 2-axis (counterclockwise around the y axis) rot_ccw_axis3: Returns a rotation matrix for a rotation of theta (in radians) about the 3-axis (counterclockwise around the z axis) �z/dim must be an integer biggen than one, got {}.z'i and j must be different, got ({}, {})rr z=i and j must be integers between 0 and {}, got i={} and j={}.)rY�int� ValueError�formatrrr �eye)rgrh�theta�dim�ij�crp�Ms r� rot_givensr��sK��~ �c�3� � �0�3��7�7��#�#)�6�#�;�;�0�0� 0� �A�v�v��(�(.��q�!� � �6�6� 6��!�f�K�K���"�c�"�"� K�b�1�f�f��S�1�W� � ��6�6<�f�S��U�A�q�6I�6I�K�K� K�1=� �E�N�N�E� �E� � �A� �E� � �A� �C���A��A�a��d�G��A�a��d�G��A�a��d�G��b�A�a��d�G� �Hrc�(�tdd|d���S)azReturns a rotation matrix for a rotation of theta (in radians) about the 3-axis. Explanation =========== For a right-handed coordinate system, this corresponds to a clockwise rotation around the `z`-axis, given by: .. math:: R = \begin{bmatrix} \cos(\theta) & \sin(\theta) & 0 \\ -\sin(\theta) & \cos(\theta) & 0 \\ 0 & 0 & 1 \end{bmatrix} Examples ======== >>> from sympy import pi, rot_axis3 A rotation of pi/3 (60 degrees): >>> theta = pi/3 >>> rot_axis3(theta) Matrix([ [ 1/2, sqrt(3)/2, 0], [-sqrt(3)/2, 1/2, 0], [ 0, 0, 1]]) If we rotate by pi/2 (90 degrees): >>> rot_axis3(pi/2) Matrix([ [ 0, 1, 0], [-1, 0, 0], [ 0, 0, 1]]) See Also ======== rot_givens: Returns a Givens rotation matrix (generalized rotation for any number of dimensions) rot_ccw_axis3: Returns a rotation matrix for a rotation of theta (in radians) about the 3-axis (counterclockwise around the z axis) rot_axis1: Returns a rotation matrix for a rotation of theta (in radians) about the 1-axis (clockwise around the x axis) rot_axis2: Returns a rotation matrix for a rotation of theta (in radians) about the 2-axis (clockwise around the y axis) rr rx�r��r��rs r� rot_axis3r�'���h �a��E�q� )� )� )�)rc�(�tdd|d���S)a�Returns a rotation matrix for a rotation of theta (in radians) about the 2-axis. Explanation =========== For a right-handed coordinate system, this corresponds to a clockwise rotation around the `y`-axis, given by: .. math:: R = \begin{bmatrix} \cos(\theta) & 0 & -\sin(\theta) \\ 0 & 1 & 0 \\ \sin(\theta) & 0 & \cos(\theta) \end{bmatrix} Examples ======== >>> from sympy import pi, rot_axis2 A rotation of pi/3 (60 degrees): >>> theta = pi/3 >>> rot_axis2(theta) Matrix([ [ 1/2, 0, -sqrt(3)/2], [ 0, 1, 0], [sqrt(3)/2, 0, 1/2]]) If we rotate by pi/2 (90 degrees): >>> rot_axis2(pi/2) Matrix([ [0, 0, -1], [0, 1, 0], [1, 0, 0]]) See Also ======== rot_givens: Returns a Givens rotation matrix (generalized rotation for any number of dimensions) rot_ccw_axis2: Returns a rotation matrix for a rotation of theta (in radians) about the 2-axis (clockwise around the y axis) rot_axis1: Returns a rotation matrix for a rotation of theta (in radians) about the 1-axis (counterclockwise around the x axis) rot_axis3: Returns a rotation matrix for a rotation of theta (in radians) about the 3-axis (counterclockwise around the z axis) rzrrxr�r�r�s r� rot_axis2r�^r�rc�(�tdd|d���S)azReturns a rotation matrix for a rotation of theta (in radians) about the 1-axis. Explanation =========== For a right-handed coordinate system, this corresponds to a clockwise rotation around the `x`-axis, given by: .. math:: R = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos(\theta) & \sin(\theta) \\ 0 & -\sin(\theta) & \cos(\theta) \end{bmatrix} Examples ======== >>> from sympy import pi, rot_axis1 A rotation of pi/3 (60 degrees): >>> theta = pi/3 >>> rot_axis1(theta) Matrix([ [1, 0, 0], [0, 1/2, sqrt(3)/2], [0, -sqrt(3)/2, 1/2]]) If we rotate by pi/2 (90 degrees): >>> rot_axis1(pi/2) Matrix([ [1, 0, 0], [0, 0, 1], [0, -1, 0]]) See Also ======== rot_givens: Returns a Givens rotation matrix (generalized rotation for any number of dimensions) rot_ccw_axis1: Returns a rotation matrix for a rotation of theta (in radians) about the 1-axis (counterclockwise around the x axis) rot_axis2: Returns a rotation matrix for a rotation of theta (in radians) about the 2-axis (clockwise around the y axis) rot_axis3: Returns a rotation matrix for a rotation of theta (in radians) about the 3-axis (clockwise around the z axis) r rzrxr�r�r�s r� rot_axis1r��r�rc�(�tdd|d���S)a�Returns a rotation matrix for a rotation of theta (in radians) about the 3-axis. Explanation =========== For a right-handed coordinate system, this corresponds to a counterclockwise rotation around the `z`-axis, given by: .. math:: R = \begin{bmatrix} \cos(\theta) & -\sin(\theta) & 0 \\ \sin(\theta) & \cos(\theta) & 0 \\ 0 & 0 & 1 \end{bmatrix} Examples ======== >>> from sympy import pi, rot_ccw_axis3 A rotation of pi/3 (60 degrees): >>> theta = pi/3 >>> rot_ccw_axis3(theta) Matrix([ [ 1/2, -sqrt(3)/2, 0], [sqrt(3)/2, 1/2, 0], [ 0, 0, 1]]) If we rotate by pi/2 (90 degrees): >>> rot_ccw_axis3(pi/2) Matrix([ [0, -1, 0], [1, 0, 0], [0, 0, 1]]) See Also ======== rot_givens: Returns a Givens rotation matrix (generalized rotation for any number of dimensions) rot_axis3: Returns a rotation matrix for a rotation of theta (in radians) about the 3-axis (clockwise around the z axis) rot_ccw_axis1: Returns a rotation matrix for a rotation of theta (in radians) about the 1-axis (counterclockwise around the x axis) rot_ccw_axis2: Returns a rotation matrix for a rotation of theta (in radians) about the 2-axis (counterclockwise around the y axis) r rrxr�r�r�s r� rot_ccw_axis3r��r�rc�(�tdd|d���S)a�Returns a rotation matrix for a rotation of theta (in radians) about the 2-axis. Explanation =========== For a right-handed coordinate system, this corresponds to a counterclockwise rotation around the `y`-axis, given by: .. math:: R = \begin{bmatrix} \cos(\theta) & 0 & \sin(\theta) \\ 0 & 1 & 0 \\ -\sin(\theta) & 0 & \cos(\theta) \end{bmatrix} Examples ======== >>> from sympy import pi, rot_ccw_axis2 A rotation of pi/3 (60 degrees): >>> theta = pi/3 >>> rot_ccw_axis2(theta) Matrix([ [ 1/2, 0, sqrt(3)/2], [ 0, 1, 0], [-sqrt(3)/2, 0, 1/2]]) If we rotate by pi/2 (90 degrees): >>> rot_ccw_axis2(pi/2) Matrix([ [ 0, 0, 1], [ 0, 1, 0], [-1, 0, 0]]) See Also ======== rot_givens: Returns a Givens rotation matrix (generalized rotation for any number of dimensions) rot_axis2: Returns a rotation matrix for a rotation of theta (in radians) about the 2-axis (clockwise around the y axis) rot_ccw_axis1: Returns a rotation matrix for a rotation of theta (in radians) about the 1-axis (counterclockwise around the x axis) rot_ccw_axis3: Returns a rotation matrix for a rotation of theta (in radians) about the 3-axis (counterclockwise around the z axis) rrzrxr�r�r�s r� rot_ccw_axis2r�r�rc�(�tdd|d���S)a�Returns a rotation matrix for a rotation of theta (in radians) about the 1-axis. Explanation =========== For a right-handed coordinate system, this corresponds to a counterclockwise rotation around the `x`-axis, given by: .. math:: R = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos(\theta) & -\sin(\theta) \\ 0 & \sin(\theta) & \cos(\theta) \end{bmatrix} Examples ======== >>> from sympy import pi, rot_ccw_axis1 A rotation of pi/3 (60 degrees): >>> theta = pi/3 >>> rot_ccw_axis1(theta) Matrix([ [1, 0, 0], [0, 1/2, -sqrt(3)/2], [0, sqrt(3)/2, 1/2]]) If we rotate by pi/2 (90 degrees): >>> rot_ccw_axis1(pi/2) Matrix([ [1, 0, 0], [0, 0, -1], [0, 1, 0]]) See Also ======== rot_givens: Returns a Givens rotation matrix (generalized rotation for any number of dimensions) rot_axis1: Returns a rotation matrix for a rotation of theta (in radians) about the 1-axis (clockwise around the x axis) rot_ccw_axis2: Returns a rotation matrix for a rotation of theta (in radians) about the 2-axis (counterclockwise around the y axis) rot_ccw_axis3: Returns a rotation matrix for a rotation of theta (in radians) about the 3-axis (counterclockwise around the z axis) rzr rxr�r�r�s r� rot_ccw_axis1r�:r�r)r)�modulesc ���ddlm}m}||t���}||��D]=}t |�dd�t t|������fi|��||<�>|S)aICreate a numpy ndarray of symbols (as an object array). The created symbols are named ``prefix_i1_i2_``... You should thus provide a non-empty prefix if you want your symbols to be unique for different output arrays, as SymPy symbols with identical names are the same object. Parameters ---------- prefix : string A prefix prepended to the name of every symbol. shape : int or tuple Shape of the created array. If an int, the array is one-dimensional; for more than one dimension the shape must be a tuple. \*\*kwargs : dict keyword arguments passed on to Symbol Examples ======== These doctests require numpy. >>> from sympy import symarray >>> symarray('', 3) [_0 _1 _2] If you want multiple symarrays to contain distinct symbols, you *must* provide unique prefixes: >>> a = symarray('', 3) >>> b = symarray('', 3) >>> a[0] == b[0] True >>> a = symarray('a', 3) >>> b = symarray('b', 3) >>> a[0] == b[0] False Creating symarrays with a prefix: >>> symarray('a', 3) [a_0 a_1 a_2] For more than one dimension, the shape must be given as a tuple: >>> symarray('a', (2, 3)) [[a_0_0 a_0_1 a_0_2] [a_1_0 a_1_1 a_1_2]] >>> symarray('a', (2, 3, 2)) [[[a_0_0_0 a_0_0_1] [a_0_1_0 a_0_1_1] [a_0_2_0 a_0_2_1]] <BLANKLINE> [[a_1_0_0 a_1_0_1] [a_1_1_0 a_1_1_1] [a_1_2_0 a_1_2_1]]] For setting assumptions of the underlying Symbols: >>> [s.is_real for s in symarray('a', 2, real=True)] [True, True] r)rl�ndindex)ro�_)rrlr��objectr�join�map�str)�prefixr\r/rlr��arr�indexs rrrqs���B%�$�$�$�$�$�$�$� �%��V� $� $� $�C������&�&���v�v�v�s�x�x��C����/H�/H�/H�I�&�&�$�&�&��E� � � �JrTc�����ttt������|s��fd�}n��fd�}t���}t |||�����S)aYGiven linear difference operator L of order 'k' and homogeneous equation Ly = 0 we want to compute kernel of L, which is a set of 'k' sequences: a(n), b(n), ... z(n). Solutions of L are linearly independent iff their Casoratian, denoted as C(a, b, ..., z), do not vanish for n = 0. Casoratian is defined by k x k determinant:: + a(n) b(n) . . . z(n) + | a(n+1) b(n+1) . . . z(n+1) | | . . . . | | . . . . | | . . . . | + a(n+k-1) b(n+k-1) . . . z(n+k-1) + It proves very useful in rsolve_hyper() where it is applied to a generating set of a recurrence to factor out linearly dependent solutions and return a basis: >>> from sympy import Symbol, casoratian, factorial >>> n = Symbol('n', integer=True) Exponential and factorial are linearly independent: >>> casoratian([2**n, factorial(n)], n) != 0 True c�B���|���|z��SrD��subs�rgrh�n�seqss ��r�<lambda>zcasoratian.<locals>.<lambda>�s����a����a��Q��/�/�rc�<���|��|��SrDr�r�s ��rr�zcasoratian.<locals>.<lambda>�s����a����a��+�+�r)�listr�rr[r:�det)r�r��zero�f�ks`` r� casoratianr��sp����> ��G�T�"�"� #� #�D� �,� /� /� /� /� /��� +� +� +� +� +�� �D� � �A� �!�Q��?�?� � � � � rc�$�tj|i|��S)z`Create square identity matrix n x n See Also ======== diag zeros ones )r:r~��argsr/s rr~r~�s�� �:�t� &�v� &� &�&rF��strict�unpackc�*�tj|||d�|��S)aKReturns a matrix with the provided values placed on the diagonal. If non-square matrices are included, they will produce a block-diagonal matrix. Examples ======== This version of diag is a thin wrapper to Matrix.diag that differs in that it treats all lists like matrices -- even when a single list is given. If this is not desired, either put a `*` before the list or set `unpack=True`. >>> from sympy import diag >>> diag([1, 2, 3], unpack=True) # = diag(1,2,3) or diag(*[1,2,3]) Matrix([ [1, 0, 0], [0, 2, 0], [0, 0, 3]]) >>> diag([1, 2, 3]) # a column vector Matrix([ [1], [2], [3]]) See Also ======== .matrixbase.MatrixBase.eye .matrixbase.MatrixBase.diagonal .matrixbase.MatrixBase.diag .expressions.blockmatrix.BlockMatrix r�)r:�diag)r�r��valuesr/s rr�r��s!��D �;��v�f� G� G�� G� G�Grc�&�tj||dd��S)aApply the Gram-Schmidt process to a set of vectors. Parameters ========== vlist : List of Matrix Vectors to be orthogonalized for. orthonormal : Bool, optional If true, return an orthonormal basis. Returns ======= vlist : List of Matrix Orthogonalized vectors Notes ===== This routine is mostly duplicate from ``Matrix.orthogonalize``, except for some difference that this always raises error when linearly dependent vectors are found, and the keyword ``normalize`` has been named as ``orthonormal`` in this function. See Also ======== .matrixbase.MatrixBase.orthogonalize References ========== .. [1] https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process T)� normalize� rankcheck)r`� orthogonalize)�vlist� orthonormals r� GramSchmidtr�s&��H � +� �+�� � � �rrTc���t|t��rDd|jvrtd���|jdkr|j}|���d}t|��r!t|��}|std���ntd���t|d��std|z���t|��}||z}t|��}t|��D]\\}}t|d��std|z���t|��D]%} |�|| ��||| |zf<�&�]t|��D]T} t| |��D]A} |�|| ���|| ��|| |z| |zf<�B�Ut|��D]'} t| dz|��D]} || | f|| | f<��(|S)a Compute Hessian matrix for a function f wrt parameters in varlist which may be given as a sequence or a row/column vector. A list of constraints may optionally be given. Examples ======== >>> from sympy import Function, hessian, pprint >>> from sympy.abc import x, y >>> f = Function('f')(x, y) >>> g1 = Function('g')(x, y) >>> g2 = x**2 + 3*y >>> pprint(hessian(f, (x, y), [g1, g2])) [ d d ] [ 0 0 --(g(x, y)) --(g(x, y)) ] [ dx dy ] [ ] [ 0 0 2*x 3 ] [ ] [ 2 2 ] [d d d ] [--(g(x, y)) 2*x ---(f(x, y)) -----(f(x, y))] [dx 2 dy dx ] [ dx ] [ ] [ 2 2 ] [d d d ] [--(g(x, y)) 3 -----(f(x, y)) ---(f(x, y)) ] [dy dy dx 2 ] [ dy ] References ========== .. [1] https://en.wikipedia.org/wiki/Hessian_matrix See Also ======== sympy.matrices.matrixbase.MatrixBase.jacobian wronskian r z)`varlist` must be a column or row vector.rz `len(varlist)` must not be zero.z*Improper variable list in hessian function�diffz'Function `f` (%s) is not differentiable)rYrr\rru�T�tolistr r[r|rX�zerosrmrsr�) r��varlist� constraintsr�rv�N�outr��grgrhs r�hessianr�Es/��X�'�:�&�&�&� �G�M� !� !��H�I�I� I� �<�1� � ��i�G��.�.�"�"�1�%���7���G� ��L�L��� A��?�@�@� @� A��E�F�F�F� �1�f� � �H��B�Q�F�G�G�G� �K���A� �A��A� ��(�(�C��+�&�&�/�/���1��q�&�!�!� L��F��J�K�K� K��q��� /� /�A��F�F�7�1�:�.�.�C��1�q�5��M�M� /� �1�X�X�D�D���q�!��� D� D�A� !���w�q�z� 2� 2� 7� 7��� � C� C�C��A��q�1�u� � � � D� �1�X�X�"�"���q�1�u�a��� "� "�A��A�q�D� �C��1��I�I� "� �Jrc�:�t�||���S)z� Create a Jordan block: Examples ======== >>> from sympy import jordan_cell >>> from sympy.abc import x >>> jordan_cell(x, 4) Matrix([ [x, 1, 0, 0], [0, x, 1, 0], [0, 0, x, 1], [0, 0, 0, x]]) )�size� eigenvalue)r:� jordan_block)�eigenvalr�s r� jordan_cellr��s��" � � �A�(� � ;� ;�;rc�,�|�|��S)a�Return the Hadamard product (elementwise product) of A and B >>> from sympy import Matrix, matrix_multiply_elementwise >>> A = Matrix([[0, 1, 2], [3, 4, 5]]) >>> B = Matrix([[1, 10, 100], [100, 10, 1]]) >>> matrix_multiply_elementwise(A, B) Matrix([ [ 0, 10, 200], [300, 40, 5]]) See Also ======== sympy.matrices.matrixbase.MatrixBase.__mul__ )�multiply_elementwise)�A�Bs r�matrix_multiply_elementwiser��s�� � !� !�!� $� $�$rc�\�d|vr|�d��|d<tj|i|��S)z�Returns a matrix of ones with ``rows`` rows and ``cols`` columns; if ``cols`` is omitted a square matrix will be returned. See Also ======== zeros eye diag r�ru)�popr:�onesr�s rr�r��s5�� �f�}�}����C����v�� �;�� '�� '� '�'r�c�dc��|ptj|��}|�|}|r||krtd||fz���t||z��}|dkr6|�|t t |��|zdz����}t||��} |s4|D]0} t| |��\} } |� ||��| | | f<�1n@|D]=} t| |��\} } | | kr"|� ||��x| | | f<| | | f<�>| S)a�Create random matrix with dimensions ``r`` x ``c``. If ``c`` is omitted the matrix will be square. If ``symmetric`` is True the matrix must be square. If ``percent`` is less than 100 then only approximately the given percentage of elements will be non-zero. The pseudo-random number generator used to generate matrix is chosen in the following way. * If ``prng`` is supplied, it will be used as random number generator. It should be an instance of ``random.Random``, or at least have ``randint`` and ``shuffle`` methods with same signatures. * if ``prng`` is not supplied but ``seed`` is supplied, then new ``random.Random`` with given ``seed`` will be created; * otherwise, a new ``random.Random`` with default seed will be used. Examples ======== >>> from sympy import randMatrix >>> randMatrix(3) # doctest:+SKIP [25, 45, 27] [44, 54, 9] [23, 96, 46] >>> randMatrix(3, 2) # doctest:+SKIP [87, 29] [23, 37] [90, 26] >>> randMatrix(3, 3, 0, 2) # doctest:+SKIP [0, 2, 0] [2, 0, 1] [0, 0, 1] >>> randMatrix(3, symmetric=True) # doctest:+SKIP [85, 26, 29] [26, 71, 43] [29, 43, 57] >>> A = randMatrix(3, seed=1) >>> B = randMatrix(3, seed=2) >>> A == B False >>> A == randMatrix(3, seed=1) True >>> randMatrix(3, symmetric=True, percent=50) # doctest:+SKIP [77, 70, 0], [70, 0, 0], [ 0, 0, 88] Nz4For symmetric matrices, r must equal c, but %i != %ir�) �random�Randomr|rs�sampler{r[r��divmod�randint) �rr��min�max�seed� symmetric�percent�prngr�rv�ijkrgrhs r� randMatrixr��sA��b � &�6�=��&�&�D��y� ���Z�Q�!�V�V��O�ST�VW�RX�X�Y�Y�Y� �q�1�u���B��#�~�~� �[�[��S��R�����C�!7�8�8� 9� 9�� �a�� � �A� �;�� -� -�C��#�q�>�>�D�A�q��l�l�3��,�,�A�a��d�G�G� -�� ;� ;�C��#�q�>�>�D�A�q��A�v�v�$(�L�L��c�$:�$:�:��!�Q�$��!�A�q�D�'�� �Hr�bareissc����d��D���t���}|dkr tjSt||��fd���}|�|��S)av Compute Wronskian for [] of functions :: | f1 f2 ... fn | | f1' f2' ... fn' | | . . . . | W(f1, ..., fn) = | . . . . | | . . . . | | (n) (n) (n) | | D (f1) D (f2) ... D (fn) | see: https://en.wikipedia.org/wiki/Wronskian See Also ======== sympy.matrices.matrixbase.MatrixBase.jacobian hessian c�,�g|]}t|����SrTr)�.0r�s r� <listcomp>zwronskian.<locals>.<listcomp>.s��/�/�/������/�/�/rrc�<���|��|��SrD)r�)rgrh� functions�vars ��rr�zwronskian.<locals>.<lambda>2s���)�A�,�"3�"3�C��";�";�r)r[r�Oner:r�)r�r�r)r��Ws`` r� wronskianr�sb����.0�/�Y�/�/�/�I� �I���A��A�v�v��u� ��q�!�;�;�;�;�;�<�<�A� �5�5��=�=�rc�\�d|vr|�d��|d<tj|i|��S)z�Returns a matrix of zeros with ``rows`` rows and ``cols`` columns; if ``cols`` is omitted a square matrix will be returned. See Also ======== ones eye diag r�ru)r�r:r�r�s rr�r�6s5�� �f�}�}����C����v�� �<�� (�� (� (�(r)rxrK)F)rT)Nrr�NFr�N)r�)<r��sympy.core.basicr�sympy.core.singletonr�sympy.core.symbolr�sympy.core.sympifyr�(sympy.functions.elementary.trigonometricrr �sympy.utilities.decoratorr �sympy.utilities.exceptionsr �sympy.utilities.iterablesr � exceptionsr�decompositionsrr� matrixbaser� repmatrixrr�solversrr�__doctest_requires__rrr^r`� MutableMatrixr:r�rqrwr�r�r�r�r�r�r�rr�r~r�r�r�r�r�r�r�r�r�rTrr�<module>rs~�� � � � �"�"�"�"�"�"�"�"�"�"�"�"�$�$�$�$�$�$�&�&�&�&�&�&�=�=�=�=�=�=�=�=�8�8�8�8�8�8�@�@�@�@�@�@�1�1�1�1�1�1�"�"�"�"�"�"�8�8�8�8�8�8�8�8�"�"�"�"�"�"�2�2�2�2�2�2�2�2�E�E�E�E�E�E�E�E�&��y�1����� FE�FE�FE�FE�FE�)�FE�FE�FE�R  �  �  �6�6�6�6�6��&6�6�6�6�",�+� ���  �  �  �  �!�  �  �  �  �,t �t �t �t �n4*�4*�4*�n4*�4*�4*�n4*�4*�4*�n4*�4*�4*�n4*�4*�4*�n4*�4*�4*�n��J�'�'�'�E�E�(�'�E�X(!�(!�(!�(!�V '� '� '��e�"H�"H�"H�"H�"H�J&�&�&�&�RJ�J�J�J�Z<�<�<�(%�%�%�&(�(�(�$?D�!%�I �I �I �I �X����>)�)�)�)�)r
Memory