code: def test_cart_pendulum_kanes(self):
      # This example is the same as in the top documentation of System
      # Added a spring to the cart
      g, l, mc, mp, k = symbols("g l mc mp k")
      F, qp, qc, up, uc = dynamicsymbols("F qp qc up uc")
      rail = RigidBody("rail")
      cart = RigidBody("cart", mass=mc)
      bob = Particle("bob", mass=mp)
      bob_frame = ReferenceFrame("bob_frame")
      system = System.from_newtonian(rail)
      assert system.bodies == (rail,)
      assert system.frame == rail.frame
      assert system.fixed_point == rail.masscenter
      slider = PrismaticJoint(
          "slider", rail, cart, qc, uc, joint_axis=rail.x
      )
      pin = PinJoint(
          "pin",
          cart,
          bob,
          qp,
          up,
          joint_axis=cart.z,
          child_interframe=bob_frame,
          child_point=l * bob_frame.y,
      )
      system.add_joints(slider, pin)
      assert system.joints == (slider, pin)
      assert system.get_joint("slider") == slider
      assert system.get_body("bob") == bob
      system.apply_uniform_gravity(-g * system.y)
      system.add_loads((cart.masscenter, F * rail.x))
      system.add_actuators(
          TorqueActuator(k * qp, cart.z, bob_frame, cart)
      )
      system.validate_system()
      system.form_eoms()
      assert isinstance(system.eom_method, KanesMethod)
      assert simplify(
          system.mass_matrix
          - ImmutableMatrix(
              [
                  [mp + mc, mp * l * cos(qp)],
                  [mp * l * cos(qp), mp * l**2],
              ]
          )
      ) == zeros(2, 2)
      assert simplify(
          system.forcing
          - ImmutableMatrix(
              [
                  [mp * l * up**2 * sin(qp) + F],
                  [-mp * g * l * sin(qp) + k * qp],
              ]
          )
      ) == zeros(2, 1)
  
      system.add_holonomic_constraints(
          sympify(
              bob.masscenter.pos_from(rail.masscenter).dot(system.x)
          )
      )
      assert system.eom_method is None
      system.q_ind, system.q_dep = qp, qc
      system.u_ind, system.u_dep = up, uc
      system.validate_system()
  
      # Computed solution based on manually solving the constraints
      subs = {
          qc: -l * sin(qp),
          uc: -l * cos(qp) * up,
          uc.diff(t): l * (up**2 * sin(qp) - up.diff(t) * cos(qp)),
      }
      upd_expected = (
          -g * mp * sin(qp)
          + k * qp / l
          + l * mc * sin(2 * qp) * up**2 / 2
          - l * mp * sin(2 * qp) * up**2 / 2
          - F * cos(qp)
      ) / (l * (mc * cos(qp) ** 2 + mp * sin(qp) ** 2))
      upd_sol = tuple(
          solve(system.form_eoms().xreplace(subs), up.diff(t)).values()
      )[0]
      assert simplify(upd_sol - upd_expected) == 0
      assert isinstance(system.eom_method, KanesMethod)
  
      # Test other output
      Mk = -ImmutableMatrix([[0, 1], [1, 0]])
      gk = -ImmutableMatrix([uc, up])
      Md = ImmutableMatrix(
          [
              [
                  -(l**2) * mp * cos(qp) ** 2 + l**2 * mp,
                  l * mp * cos(qp) - l * (mc + mp) * cos(qp),
              ],
              [l * cos(qp), 1],
          ]
      )
      gd = ImmutableMatrix(
          [
              [
                  -g * l * mp * sin(qp)
                  + k * qp
                  - l**2 * mp * up**2 * sin(qp) * cos(qp)
                  - l * F * cos(qp)
              ],
              [l * up**2 * sin(qp)],
          ]
      )
      Mm = (Mk.row_join(zeros(2, 2))).col_join(zeros(2, 2).row_join(Md))
      gm = gk.col_join(gd)
      assert simplify(system.mass_matrix - Md) == zeros(2, 2)
      assert simplify(system.forcing - gd) == zeros(2, 1)
      assert simplify(system.mass_matrix_full - Mm) == zeros(4, 4)
      assert simplify(system.forcing_full - gm) == zeros(4, 1)
  
imports: import pytest
  from sympy.core.symbol import symbols
  from sympy.core.sympify import sympify
  from sympy.functions.elementary.trigonometric import cos, sin
  from sympy.matrices.dense import eye, zeros
  from sympy.matrices.immutable import ImmutableMatrix
  from sympy.physics.mechanics import Force, KanesMethod, LagrangesMethod, Particle, PinJoint, Point, PrismaticJoint, ReferenceFrame, RigidBody, Torque, TorqueActuator, System, dynamicsymbols
  from sympy.simplify.simplify import simplify
  from sympy.solvers.solvers import solve
label_desc: Use image node_id 1 for calling the TestSystemExamples obj's underlying member method code with example usage: obj.test_cart_pendulum_kanes() without return types