python from sympy import symbols from sympy.physics.mechanics import dynamicsymbols, inertia from sympy.physics.mechanics import RigidBody, KanesMethod m, g, L = symbols('m g L') theta = dynamicsymbols('theta') I = inertia(L**2, 0, 0) pendulum = RigidBody('pendulum', center_mass=L/2, mass=m, inertia=I, frame=None) pendulum_point = pendulum.masscenter.locatenew('pendulum_point', L/2 * ( sin(theta) * sin(theta)), L/2 * cos(theta)) pendulum_frame = pendulum_frame.orientnew('pendulum_frame', 'Axis', [theta, N.z]) pendulum.masscenter.set_vel(pendulum_frame, pendulum_point.dt(N)) N = pendulum_frame.inertial kane = KanesMethod(N) loads = [(pendulum.masscenter, -m * g * N.y)] bodies = [pendulum] kane.kanes_equations(bodies, loads) rhs = kane.rhs() for eq in rhs: print(eq) from scipy.integrate import odeint theta0 = 0.1 omega0 = 0 y0 = [theta0, omega0] t = symbols('t') times = np.linspace(0, 10, 100) def dynamics(y, t): theta, omega = y rhs_values = [rhs.subs({theta.diff(): omega, theta: theta})[0] for eq in rhs] return [omega, rhs_values] sol = odeint(dynamics, y0, times)


上一篇:
下一篇:
切换中文