python
from sympy.physics.mechanics import dynamicsymbols
from sympy import symbols
from sympy.physics.mechanics import ReferenceFrame, Point, Particle
from sympy.physics.mechanics import RigidBody, KanesMethod
m, g, L, t = symbols('m g L t')
x = dynamicsymbols('x')
N = ReferenceFrame("N")
P = Point("P")
P.set_vel(N, 0)
A = N.orientnew("A", "Axis", [x, N.z])
A.set_ang_vel(N, x.diff(t) * N.z)
Pa = Particle("Pa", P, m)
Pa.set_masscenter(P)
Pa.mass = m
I = m * L**2 / 12
rigid_body = RigidBody("rigid_body", P, A, Pa, (I, P))
gravitational_force = (P, -m * g * N.y)
kane = KanesMethod(N, q_ind=[x], u_ind=[x.diff(t)], kd_eqs=[x - L/2], q_dependent=[x.diff(t)], configuration_constraints=[x - L/2])
bodies = [rigid_body]
forces = [gravitational_force]
fr, fr_star = kane.kanes_equations(forces, bodies)
kane.mass_matrix_full
kane.forcing_full
kane.linearize()