Approximating networks and extended Ritz method for the solution of functional optimization problems