Given $(e_n)_{-N\le n\le N}\in\mathbb R^{2N+1}$ and $-1<x<1$, solve
\begin{eqnarray} &&\max_{(q_n)_{-N\le n\le N}\in\mathbb R^{2N+1}_+}~ \sum_{n=-N}^N (e_n-\log(q_n))q_n \\ \mbox{s.t.} &&\quad \sum_{n=-N}^N q_n=1 \mbox{ and } \sum_{n=-N}^N nq_n/N=x. \end{eqnarray}
My question is whether we have (very efficient) packages (C++ or Python) to solve numerically this convex optimization problem? E.g. processing time less than 0.1 second with $N=100$. The motivation comes from my previous question, and I need to solve 40,000 optimization problems of this type to construct a discrete Markov martingale.
Any answers and comments are highly appreciated!
My thoughts : Introduce the Lagrangian multipliers and define
$$L(q_{-N},\ldots, q_N,\lambda_1,\lambda_2):=\sum_{n=-N}^N (e_n-\log(q_n))q_n+\lambda_1(\sum_{n=-N}^N q_n-1)+\lambda_2(\sum_{n=-N}^N nq_n/N-x).$$
Setting $\partial_{q_n}L=e_n-\log(q_n)-1+\lambda_1+n\lambda_2/N=0$, $\partial_{\lambda_1}L=\sum_{n=-N}^Nq_n-1=0$ and $\partial_{\lambda_2}L=\sum_{n=-N}^Nnq_n/N-x=0$, one has $q_n=\exp(e_n-1+\lambda_1+n\lambda_2/N)$ and thus
$$\sum_{n=-N}^N \exp(e_n-1+\lambda_1+n\lambda_2/N)=1\quad \mbox{and}\quad \sum_{n=-N}^N \exp(e_n-1+\lambda_1+n\lambda_2/N)n/N=x.$$
We obtain finally
$$\sum_{n=-N}^N \exp(e_n+n\lambda_2/N)(n/N-x)=0.$$
Let $z:=\exp(\lambda_2/N)$, one has
$$\sum_{n=-N}^N \exp(e_n)z^{n}(n/N-x)=0=\sum_{n=-N}^N \exp(e_n)z^{n+N}(n/N-x).$$
Define $A_k:=\exp(e_{k-N})(k/N-1-x)$ for $0\le k\le 2N+1$. Then solving the above opitmization problem is equivalent to search for the strictly positive root of the polynomial $\sum_{k=0}^{2N+1}A_kz^k=0$. Is there any quick solver for this?