The method of least squares for boundary value problems