Recent research and new paradigms in mathematics, engineering, and science assume nonlinear signal models of the form M = (i is an element of I) V-i consisting of a union of subspaces Vi instead of a single subspace M = V. These models have been used in sampling and reconstruction of signals with finite rate of innovation, the Generalized Principle Component Analysis and the subspace segmentation problem in computer vision, and problems related to sparsity, compressed sensing, and dictionary design. In this paper, we develop an algorithm that searches for the best nonlinear model of the form M = (sic)(i=1)(l) V-i subset of R-N that is optimally compatible with a set of observations F = {f(1), ... , f(m)} subset of R-N. When l = 1 this becomes the classical least squares optimization. Thus, this problem is a nonlinear version of the least squares problem. We test our algorithm on synthetic data as well as images.