New approach to the calculation of density functionals