In this paper the optimal control algorithm for discrete time systems minimizing a quadratic cost functional is derived. The system considered is assumed to be linear and to possess an exogenous component. The cost functional is a quadratic tracking equation in which it is assumed that the weighting matrices are semi-positive definite. and moreover that a weighted sum of these matrices is positive definite. The time horizon considered is infinite. Two special cases of the obtained controller are the controller minimizing the infinite time Minimum Variance cost criterium and the LQ-regulator. For the infinite time Minimum Variance controller a characterization of the admissible reference trajectories is given.