Solution (source code)

= Solution

Assume the <covariance matrix> $\Sigma$ is positive definite and the excess-mean vector $d=z-R\mathbf1$ is nonzero. Put $A=d^t\Sigma^{-1}d>0$. Substituting $w=\lambda\Sigma^{-1}d$ in the mean constraint gives $\lambda A=\mu-R$. Therefore
$$
\boxed{\lambda=\frac{\mu-R}{d^t\Sigma^{-1}d}.}
$$
These weights are indeed the minimum-variance solution, not just a stationary point. Any other feasible vector is $w+v$ with $d^tv=0$. Its <variance> is $w^t\Sigma w+2\lambda d^tv+v^t\Sigma v=w^t\Sigma w+v^t\Sigma v$, which is strictly larger unless $v=0$. If $d=0$, only mean $R$ is feasible, and the minimum-risk <portfolio> invests entirely in the <risk-free asset>; the multiplier formula with zero denominator is not applicable.