python
import sympy as sp
from pydy.system import System
m, l, g, t = sp.symbols('m l g t')
x1, x2 = sp.symbols('x1 x2', cls=sp.Function)
q = sp.Matrix([x1(t), x2(t)])
u = sp.Function('u')(t)
coords = [x1(t), x2(t)]
speeds = [x1(t).diff(t), x2(t).diff(t)]
for q_i, u_i in zip(q, speeds):
system = [u_i]
system.append((m * l**2 * q_i.diff(t, t) + m * g * l * sp.cos(q_i)))
qdot = sp.Matrix(speeds)
x = sp.Matrix(coords + speeds)
xdot = x.jacobian(qdot) * qdot
L = m * l**2 / 3
system = sp.Matrix(system)
inputs = sp.Matrix([u])
c = sp.Matrix([0])
x_funcs = sp.Matrix(coords + speeds)
u_funcs = sp.Matrix([u])
sys = System(rhs, q, x_funcs, [0], system, inputs, [0], c, coordinate_symbols=q, constant_symbols=[m, l, g])
sys.times = sp.symbols('t', real=True)
times = sp.linspace(0, 10, 100)
x = sys.integrate(times)
sp.pprint(x)