Existence and non existence of solutions to a variational problem on a square