This paper introduced a dynamical system (neural networks) algorithm for solving a least squares problem with orthogonality constraints, which has wide applications in computer vision and signal processing. A rigorous analysis for the convergence and stability of the algorithm was provided. Moreover, a so called zero extension technique was presented to keep the algorithm always convergent to the needed result for any randomly chosen initial data. Numerical experiments illustrate the effectiveness and efficiency of the algorithm.