11. The terms of the sequence $\left\{a_{n}\right\}$ are positive, and the sum of its first $n$ terms $S_{n}=\frac{1}{2}\left(a_{n}+\frac{1}{a_{n}}\right)$. Then $a_{n}=$ $\qquad$
11. $\sqrt{n}-\sqrt{n-1}$.

From $a_{1}=S_{1}=\frac{1}{2}\left(a_{1}+\frac{1}{a_{1}}\right)$, we get $a_{1}=\frac{1}{a_{1}}$.
Given $a_{1}>0$, we have $a_{1}=1, S_{1}=1$.
When $n>1$, from
$$
S_{n}=\frac{1}{2}\left(a_{n}+\frac{1}{a_{n}}\right) \text {, }
$$

we know $S_{n-1}+a_{n}=\frac{1}{2}\left(a_{n}+\frac{1}{a_{n}}\right)$, which means
$S_{n-1}=\frac{1}{2}\left(-a_{n}+\frac{1}{a_{n}}\right)$.
(1) + (2) gives $S_{n}+S_{n-1}=\frac{1}{a_{n}}$.
Also, $S_{n}-S_{n-1}=a_{n}$,
(3) $\times$ (4) yields $S_{n}^{2}-S_{n-1}^{2}=1$.
Therefore, $\left\{S_{n}^{2}\right\}$ is an arithmetic sequence, with the first term and common difference both being 1.
Thus, $S_{n}^{2}=n$. Hence, $S_{n}=\sqrt{n}$.
Therefore, when $n>1$, $a_{n}=S_{n}-S_{n-1}=\sqrt{n}-\sqrt{n-1}$.
When $n=1$, the above formula also holds.