
    sg?                     :    d Z ddlmZ ddlmc mZ 	 	 ddZddZ	y)zOThis module contains some sample symbolic models used for testing and
examples.    )backendNc                    t        j                  dj                  |             }t        j                  dj                  |             }t        j                  dj                  |             }t        j                  d      }t        j                  dj                  |             }t        j                  dj                  |             }t        j                  dj                  |             }	t        j
                  d      }
t        j                  d	      }|j                  |
d
       |g}g }g }g }t        |       D ]W  }|d   j                  dj                  |      ||   |
j                  z        }|j                  |
|d   j                  |
      ||   |
j                  z  z          |j                  |       t        j                  dj                  |      |||         }|j                  ||   ||   j                         z
         ||    ||   z  ||   ||   z  z
  }	 |||dz      ||dz      z  ||dz      ||dz      z  z   z  }|r|||   |z  z  }|r||	|   z  }|j                  |||
j                  z  f       |j                  |       Z t        j                   |
|||      }|j#                  ||       |S # t        $ r Y w xY w)as  Returns a system containing the symbolic equations of motion and
    associated variables for a simple multi-degree of freedom point mass,
    spring, damper system with optional gravitational and external
    specified forces. For example, a two mass system under the influence of
    gravity and external forces looks like:

    ::

        ----------------
         |     |     |   | g
         \    | |    |   V
      k0 /    --- c0 |
         |     |     | x0, v0
        ---------    V
        |  m0   | -----
        ---------    |
         | |   |     |
         \ v  | |    |
      k1 / f0 --- c1 |
         |     |     | x1, v1
        ---------    V
        |  m1   | -----
        ---------
           | f1
           V

    Parameters
    ==========

    n : integer
        The number of masses in the serial chain.
    apply_gravity : boolean
        If true, gravity will be applied to each mass.
    apply_external_forces : boolean
        If true, a time varying external force will be applied to each mass.

    Returns
    =======

    kane : sympy.physics.mechanics.kane.KanesMethod
        A KanesMethod object.

    m:{}zk:{}zc:{}gzx:{}zv:{}zf:{}Noriginr   zcenter{}zblock{}   q_indu_indkd_eqs)smsymbolsformatmedynamicsymbolsReferenceFramePointset_velrange	locatenewxvelappendParticlediff
IndexErrorKanesMethodkanes_equations)napply_gravityapply_external_forcesmass	stiffnessdampingacceleration_due_to_gravitycoordinatesspeeds
specifiedsceilingr   pointskinematic_equations	particlesforcesicenterblocktotal_forcekanes                        Q/var/www/html/venv/lib/python3.12/site-packages/sympy/physics/mechanics/models.pymulti_mass_spring_damperr6   
   s   \ ::fmmA&'D

6==+,Ijjq)*G"$**S/##FMM!$45Kv}}Q/0F""6==#34J$GXXhF
NN7AXFIF1X  %%j&7&7&:&1!nwyy&@Bwr
w 7ay799,!- 	.fI,,Q/aA""6!9{1~/B/B/D#DE!!}{1~5qzF1I-.	Ia!e,{1q5/AA#AENVAE]:; <K
 47%@@@K :a=(Kv{WYY6789 < >>'F!46DF+K#  		s   (&K	KKc                    | dk  rt        d      t        j                  dj                  | dz               }t        j                  dj                  | dz               }|du r't        j                  dj                  | dz               }t	        j
                  dj                  | dz               }t	        j
                  d	j                  |             }t	        j
                  d
      \  }}	t        j                  d      }
t        j                  d      }|j                  |
d       t        j                  d      }|j                  ||d   |
j                  z         |j                  |
|d   |
j                  z         t        j                  d||d         }|
g}|g}|g}||d    |z  |
j                  z  fg}|d   j                  |	      |d   z
  g}|du s|du rg }nd}t        |       D ]  }|
j                  dj                  |      d||dz      |
j                   g      }|j#                  |
||dz      |
j                   z         |j%                  |       |d   j'                  dj                  |dz         ||   |j                  z        }|j)                  |d   |
|       |j%                  |       t        j                  dt+        |dz         z   |||dz            }|j%                  |       |j%                  |||dz       |z  |
j                  z  f       |du r|j%                  |          |dk(  r$|j%                  |
||    |
j                   z  f       || dz
  k(  r$|j%                  |||   |
j                   z  f       n9|j%                  |||   |
j                   z  ||dz      |
j                   z  z
  f       |j%                  ||dz      j                  |	      ||dz      z
         
 |du rFt        j                  d      }|j%                  |||
j                  z  f       |j%                  |       t        j,                  |
|||      }|j/                  ||       |S )a-  Returns the system containing the symbolic first order equations of
    motion for a 2D n-link pendulum on a sliding cart under the influence of
    gravity.

    ::

                  |
         o    y   v
          \ 0 ^   g
           \  |
          --\-|----
          |  \|   |
      F-> |   o --|---> x
          |       |
          ---------
           o     o

    Parameters
    ==========

    n : integer
        The number of links in the pendulum.
    cart_force : boolean, default=True
        If true an external specified lateral force is applied to the cart.
    joint_torques : boolean, default=False
        If true joint torques will be added as specified inputs at each
        joint.

    Returns
    =======

    kane : sympy.physics.mechanics.kane.KanesMethod
        A KanesMethod object.

    Notes
    =====

    The degrees of freedom of the system are n + 1, i.e. one for each
    pendulum link and one for the lateral motion of the cart.

    M x' = F, where x = [u0, ..., un+1, q0, ..., qn+1]

    The joint angles are all defined relative to the ground where the x axis
    defines the ground line and the y axis points up. The joint torques are
    applied between each adjacent link and the between the cart and the
    lower link where a positive torque corresponds to positive angle.

    r   z/The number of links must be a positive integer.zq:{}r
   zu:{}TzT1:{}r   zl:{}zg tIOP0Pa0NzB{}Axisr	   zP{}PaFr   )
ValueErrorr   r   r   r   r   r   r   r   set_posr   r   yr   r   	orientnewzset_ang_velr   r   v2pt_theorystrr   r    )r!   
cart_forcejoint_torquesquTmlr   tr8   r9   r:   r;   framesr,   r.   r/   kindiffs	specifiedr0   BiPiPair>   r4   s                             r5   n_link_pendulum_on_cartrU   p   s   b 	AvJKK
&--A./A
&--A./AgnnQU34


6==Q'(A


6==#$A::eDAq
#A
AIIaO	$BJJq!A$*JJq!A$*
++eR1
&CSFTFIAaD519qss?#$F!		!qt#$HT]d2		1X 5[[a&1QU8QSS/B
q!AE(QSS.)bBZ!!%,,q1u"5qtbdd{C
vbz1b)bkk$QU+R1q5:rAa!eH9q=133./0D QqT"Avq1Q4%!##+./AEzr1Q4!##:./r1Q4!##:!a%133#>?@!a%a(1QU834558 Tc"r1qss7m$>>!1Ah?DF+K    )r
   FF)r
   TF)
__doc__
sympy.corer   r   sympy.physics.mechanicsphysics	mechanicsr   r6   rU    rV   r5   <module>r]      s*    % $ $ 1638cLvrV   