https://github.com/colgreen/cartpole-physics
Note that the equations being used in the 'wild' are generally wrong in some way; see the article appendices for detailed info.