# Projecting a nonnegative vector onto the simplex

Given an elementwise nonnegative vector $y$, I'd like to find the projection of $y$ onto the simplex $S: \{ (x_1, \ldots, x_n) ~|~ \sum_{i=1}^n x_i=1, x_i \geq 0 \mbox{ for all } i \}$.

Is there a closed form expression for this? If not, I need to write a computer program which will compute this projection; is there something simple I could do to compute this?

Simplicity is more important to me than running time; I don't want to spend a long time coding this. I do realize this is a convex optimization problem and could be solved by using various optimization solvers, but that seems like overkill.

-
Do you mean the projection from the origin? If so, the answer is simply $y/s$, where $s$ is the sum of the coordinates of $y$. – Jim Belk Jun 18 '11 at 18:24
@Jim Belk - I meant "projection" to mean the map which sends $y$ to the closest point to it in $S$. Sadly, this does not turn out to equal $y/s$. – robinson Jun 18 '11 at 22:55
– Wok Oct 29 '12 at 12:43