Some applications of the least squares method to differential equations