Integrate your residuals while solving optimization problems with differential equations