A numerically stable method to calculate the quantum states of carriers based on the variational principle is proposed. It is especially effective for the carriers confined in the quantum wells under the influence of self-interaction of the carriers. In this treatment, a wave function is defined as a set of scalar numbers based on the finite-difference approach. An action defined as the expectation value of a Hamiltonian becomes a multivariate function of the wave function. Application of numerical multidimensional minimization procedures to the action can achieve stable convergence even under the conditions where the conventional self-consistent approach to Schrodinger and Poisson equations fails to give solutions. Application to the calculations of ground states in modulation-doped single quantum wells is demonstrated, and quantitative comparison to the conventional method is also presented. This method has implications not only for numerical procedures, but also for the numerical realization of the variational principle, a fundamental concept in physics.