Invariant formulas for the Euler-Lagrange equation associated to sub-Riemannian geodesics