Skip to content Skip to sidebar Skip to footer

Pendulum Simulation In Python Using Odeint() Not Quite Working As A Pendulum

I have built a pendulum simulation using fourth order Runge-Kutta differentiation where everything is done step by step: from scipy import * from matplotlib.pyplot import * ##A pen

Solution 1:

You've got mistakes in your derivative function for the motion for the pendulum.

In python ^ is exclusive-or operator, rather than the power operator, which is **. So you'll to use l**2. Also, AFAICT, the first element of the state vector should actually be y[1]. From similar work in the past this worked (assumed m = 1 and l = 1).

def simple_pendulum_deriv(x, t, g = 9.81, mu = 0.5): 
    nx = np.zeros(2)
    nx[0] = x[1]
    nx[1] = -(g * np.sin(x[0])) - mu*x[1]
    return nx

Post a Comment for "Pendulum Simulation In Python Using Odeint() Not Quite Working As A Pendulum"