It is shown that the phase-shift analysis of elastic-scattering data leads to a set of illposed, non-linear, stochastic equations. An algorithm is presented and tested which allows to find a solution, irrespective of the quality of the data. It makes use of a-priori information and determines the minimal amount of such information necessary to achieve a unique fit. The significance of the solution and its associated errors are discussed.