Solution (source code)

= Solution

Introduce a second multiplier $b$ and use
$$
\mathcal L=-\sum_i x_i\log x_i-\lambda\left(\sum_i x_i-1\right)
-b\left(\sum_i x_i y_i-Y\right).
$$
The stationary equations become $-\log x_i-1-\lambda-by_i=0$. Writing $a=e^{-1-\lambda}>0$ gives
$$
\boxed{x_i=ae^{-by_i}}.
$$
The two constraints determine the constants through
$$
\boxed{a\sum_{i=1}^n e^{-by_i}=1,\qquad
a\sum_{i=1}^n y_i e^{-by_i}=Y}.
$$
Equivalently, $a=1/Z(b)$ with $Z(b)=\sum_i e^{-by_i}$, and $-d\log Z/db=Y$. This is the <maximum entropy distribution with a prescribed finite mean>.

For nonconstant $y_i$, a strictly positive solution exists exactly when $\min_i y_i<Y<\max_i y_i$. The mean's <derivative> with respect to $b$ is $-\operatorname{Var}_b(y)<0$, so $b$ is unique in that case. At either extreme mean no strictly positive solution exists. If all $y_i=y_0$, feasibility requires $Y=y_0$ and the extra <constraint> is redundant: $x_i=1/n$, while $a,b$ are not separately identifiable. The negative entropy Hessian ensures that any feasible interior <stationary point> is the unique constrained maximum.