K i^<ddlmZddlmZddlmZddlmZmZddl m Z m Z m Z ddl mZddlmZddlmZdd lmZdd lmZdd ZdZdZdZdZdZdZdZdZd ddZ y )) CoordSys3D)Del) BaseScalar)Vector BaseVector)gradientcurl divergence)diff)S) integrate)sympify)DyadicNFc  |dtjfvr|St|ts t dt|tr| t d|rp|j ttDchc]}|jc}|hz }i}|D]"}|j|j|$|j|}tj}|j} | D]E}||k7r6|j|| |j|z} |t!| |z }>|| |z }G|St|t"r||}t|ts t dt"j} |} |j$j'D]N\} }| t)||| t)| j*d|| t)| j*d|| zzz } P| S| t d|rt-}t/|}|j tD]-}|j|k7s|j1|j/i}|D]"}|j|j|$|j|S|Scc}w)aK Global function for 'express' functionality. Re-expresses a Vector, Dyadic or scalar(sympyfiable) in the given coordinate system. If 'variables' is True, then the coordinate variables (base scalars) of other coordinate systems present in the vector/scalar field or dyadic are also substituted in terms of the base scalars of the given system. Parameters ========== expr : Vector/Dyadic/scalar(sympyfiable) The expression to re-express in CoordSys3D 'system' system: CoordSys3D The coordinate system the expr is to be expressed in system2: CoordSys3D The other coordinate system required for re-expression (only for a Dyadic Expr) variables : boolean Specifies whether to substitute the coordinate variables present in expr, in terms of those of parameter system Examples ======== >>> from sympy.vector import CoordSys3D >>> from sympy import Symbol, cos, sin >>> N = CoordSys3D('N') >>> q = Symbol('q') >>> B = N.orient_new_axis('B', q, N.k) >>> from sympy.vector import express >>> express(B.i, N) (cos(q))*N.i + (sin(q))*N.j >>> express(N.x, B, variables=True) B.x*cos(q) - B.y*sin(q) >>> d = N.i.outer(N.i) >>> express(d, B, N) == (cos(q))*(B.i|N.i) + (-sin(q))*(B.j|N.i) True rz>system should be a CoordSys3D instancezJsystem2 should not be provided for VectorszCsystem2 should be a CoordSys3D instance variables)rzero isinstancer TypeError ValueErroratomsrrsystemupdate scalar_mapsubsseparaterotation_matrix to_matrixmatrix_to_vectorr componentsitemsexpressargssetradd)exprrsystem2rx system_list subs_dictfoutvecpartstempoutdyadvarkv system_sets \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/vector/functions.pyr#r# s` 6;; fj )"# #$  )* * .2ZZ J-OP188PTZS[[KI  7  f!56 799Y'D  #AF{--a0583E3Ea3HH*488%("  #  D& ! ?G':.&' '++OO))+ FDAq 6S9 FcB GsCDE FG F   )* * J4=DZZ + -88v%NN188, -I 7  f!56 799Y' ' _Qs-JcZddlm}||}t|dkDrtt |}t ||d}|j \}}}|j\}}} tj||t||z} | tj||t||zz } | tj||t|| zz } | dk(r t|trtj} | St|trtjStjS)a Returns the directional derivative of a scalar or vector field computed along a given vector in coordinate system which parameters are expressed. Parameters ========== field : Vector or Scalar The scalar or vector field to compute the directional derivative of direction_vector : Vector The vector to calculated directional derivative along them. Examples ======== >>> from sympy.vector import CoordSys3D, directional_derivative >>> R = CoordSys3D('R') >>> f1 = R.x*R.y*R.z >>> v1 = 3*R.i + 4*R.j + R.k >>> directional_derivative(f1, v1) R.x*R.y + 4*R.x*R.z + 3*R.y*R.z >>> f2 = 5*R.x**2*R.z >>> directional_derivative(f2, v1) 5*R.x**2 + 30*R.x*R.z r)_get_coord_systemsTr)sympy.vector.operatorsr7lennextiterr# base_vectors base_scalarsrdotr rrr Zero) fielddirection_vectorr7 coord_sysijr2r)yzouts r5directional_derivativerH~s::"5)I 9~i) yD9((*1a((*1ajj)1-UA> vzz*A.eQ?? vzz*A.eQ?? !8 5&1++C E6 "{{vv ct}|jr7tt|t t |z j S|j ||j S)a! Return the laplacian of the given field computed in terms of the base scalars of the given coordinate system. Parameters ========== expr : SymPy Expr or Vector expr denotes a scalar or vector field. Examples ======== >>> from sympy.vector import CoordSys3D, laplacian >>> R = CoordSys3D('R') >>> f = R.x**2*R.y**5*R.z >>> laplacian(f) 20*R.x**2*R.y**3*R.z + 2*R.y**5*R.z >>> f = R.x**2*R.i + R.y**3*R.j + R.z**4*R.k >>> laplacian(f) 2*R.i + 6*R.y*R.j + 12*R.z**2*R.k )r is_Vectorrr r doitr>)r'delops r5 laplacianrNsU2 EE ~~D)*T$t*-==CCEE 99U4[ ! & & ((rIct|ts td|tjk(ryt |j tjk(S)a Checks if a field is conservative. Parameters ========== field : Vector The field to check for conservative property Examples ======== >>> from sympy.vector import CoordSys3D >>> from sympy.vector import is_conservative >>> R = CoordSys3D('R') >>> is_conservative(R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k) True >>> is_conservative(R.z*R.j) False field should be a VectorT)rrrrr simplifyr@s r5is_conservativerSsE4 eV $233   ;   !V[[ 00rIct|ts td|tjk(ryt |j t juS)a Checks if a field is solenoidal. Parameters ========== field : Vector The field to check for solenoidal property Examples ======== >>> from sympy.vector import CoordSys3D >>> from sympy.vector import is_solenoidal >>> R = CoordSys3D('R') >>> is_solenoidal(R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k) True >>> is_solenoidal(R.y * R.j) False rPT)rrrrr rQr r?rRs r5 is_solenoidalrUsF4 eV $233   e  % % '166 11rIct|s td|tjk(rtj St |ts tdt||d}|j}|j}t|j|d|d}t|ddD]@\}}t|||dz}|j||z }|t|||dzz }B|S)a Returns the scalar potential function of a field in a given coordinate system (without the added integration constant). Parameters ========== field : Vector The vector field whose scalar potential function is to be calculated coord_sys : CoordSys3D The coordinate system to do the calculation in Examples ======== >>> from sympy.vector import CoordSys3D >>> from sympy.vector import scalar_potential, gradient >>> R = CoordSys3D('R') >>> scalar_potential(R.k, R) == R.z True >>> scalar_field = 2*R.x**2*R.y*R.z >>> grad_field = gradient(scalar_field) >>> scalar_potential(grad_field, R) 2*R.x**2*R.y*R.z zField is not conservativecoord_sys must be a CoordSys3DTrrrN)rSrrrr r?rrrr#r<r=r r> enumerater )r@rB dimensionsscalars temp_functionrCdim partial_diffs r5scalar_potentialr^s> 5 !455  vv  i ,899 E9 5E'')J$$&Geii 1 6 CMJqrN+A3M71q5>: yy~ 4 <Q@@ A rIct|ts tdt|tr t ||}n|}|j }t |j||d}t |j||d}i}i} |j} t|jD]3\} } | j||| | <| j|| | | <5|j| |j|z S)a) Returns the scalar potential difference between two points in a certain coordinate system, wrt a given field. If a scalar field is provided, its values at the two points are considered. If a conservative vector field is provided, the values of its scalar potential function at the two points are used. Returns (potential at point2) - (potential at point1) The position vectors of the two Points are calculated wrt the origin of the coordinate system provided. Parameters ========== field : Vector/Expr The field to calculate wrt coord_sys : CoordSys3D The coordinate system to do the calculations in point1 : Point The initial Point in given coordinate system position2 : Point The second Point in the given coordinate system Examples ======== >>> from sympy.vector import CoordSys3D >>> from sympy.vector import scalar_potential_difference >>> R = CoordSys3D('R') >>> P = R.origin.locate_new('P', R.x*R.i + R.y*R.j + R.z*R.k) >>> vectfield = 4*R.x*R.y*R.i + 2*R.x**2*R.j >>> scalar_potential_difference(vectfield, R, R.origin, P) 2*R.x**2*R.y >>> Q = R.origin.locate_new('O', 3*R.i + R.j + 2*R.k) >>> scalar_potential_difference(vectfield, R, P, Q) -2*R.x**2*R.y + 18 rWTr) rrrrr^originr# position_wrtr=rXr<r>r) r@rBpoint1point2 scalar_fnr` position1 position2 subs_dict1 subs_dict2rZrCr)s r5scalar_potential_differenceriCsZ i ,899% $UI6    F++F3Y"&(I++F3Y"&(IJJ$$&G)002321!"y!1 71:!"y!1 71:2 >>* % z(B BBrIctj}|j}t|D]\}}||||zz }|S)a Converts a vector in matrix form to a Vector instance. It is assumed that the elements of the Matrix represent the measure numbers of the components of the vector along basis vectors of 'system'. Parameters ========== matrix : SymPy Matrix, Dimensions: (3, 1) The matrix to be converted to a vector system : CoordSys3D The coordinate system the vector is to be defined in Examples ======== >>> from sympy import ImmutableMatrix as Matrix >>> m = Matrix([1, 2, 3]) >>> from sympy.vector import CoordSys3D, matrix_to_vector >>> C = CoordSys3D('C') >>> v = matrix_to_vector(m, C) >>> v C.i + 2*C.j + 3*C.k >>> v.to_matrix(C) == m True )rrr<rX)matrixrr-vectsrCr)s r5r r sK@[[F    !E&!1!eAh, MrIc|j|jk7r&tdt|zdzt|zg}|}|j*|j ||j}|j*|j |t |}g}|}||vr"|j ||j}||vr"t |}|j||j|dd||fS)z Calculates the 'path' of objects starting from 'from_object' to 'to_object', along with the index of the first common ancestor in the tree. Returns (index, list) tuple. z!No connecting path found between z and N) _rootrstr_parentappendr%r9extendindex) from_object to_object other_pathobj object_set from_pathrts r5_pathr{s IOO+<[)*,3469)nEF FJ C ++ !#kk ++ !cZJI C Z kk Z   NE Z 0 0 5 9r 9:; ) rI) orthonormalc|td|Ds tdg}t|D]j\}}t|D]}|||j ||z}|j t jr td|j|l|r|Dcgc]}|j}}|Scc}w)aO Takes a sequence of independent vectors and orthogonalizes them using the Gram - Schmidt process. Returns a list of orthogonal or orthonormal vectors. Parameters ========== vlist : sequence of independent vectors to be made orthogonal. orthonormal : Optional parameter Set to True if the vectors returned should be orthonormal. Default: False Examples ======== >>> from sympy.vector.coordsysrect import CoordSys3D >>> from sympy.vector.functions import orthogonalize >>> C = CoordSys3D('C') >>> i, j, k = C.base_vectors() >>> v1 = i + 2*j >>> v2 = 2*i + 3*j >>> orthogonalize(v1, v2) [C.i + 2*C.j, 2/5*C.i + (-1/5)*C.j] References ========== .. [1] https://en.wikipedia.org/wiki/Gram-Schmidt_process c3<K|]}t|tyw)N)rr).0vecs r5 z orthogonalize..s83z#v&8sz#Each element must be of Type Vectorz#Vector set not linearly independent) allrrXrange projectionequalsrrrrr normalize)r|vlist ortho_vlistrCtermrDrs r5 orthogonalizersF 8%8 8=>>KU#!4q 8A KN--eAh7 7D 8 ;;v{{ #BC C4 !2=>3s}}> > ?sB9)NF)!sympy.vector.coordsysrectrsympy.vector.deloperatorrsympy.vector.scalarrsympy.vector.vectorrrr8rr r sympy.core.functionr sympy.core.singletonr sympy.integrals.integralsr sympy.corersympy.vector.dyadicrr#rHrNrSrUr^rir r{rrIr5rsg0(*2==$"/&nb.b)>1B2B0fBCJ$N<',4rI