3. 1. 4 * The terms of the sequence $\left\{a_{n}\right\}$ are positive, and the sum of the first $n$ terms is $S_{n}$, satisfying $S_{n}=\frac{1}{2}\left(a_{n}+\frac{1}{a_{n}}\right)$, find the general term of the sequence $\left\{a_{n}\right\}$.
Given that $a_{1}=S_{1}=\frac{1}{2}\left(a_{1}+\frac{1}{a_{1}}\right)$, so $a_{1}=\frac{1}{a_{1}}$, and since $a_{1}>0$, we have $a_{1}=1$. Thus, $S_{1}=1$. When $n>1$, from $S_{n}=\frac{1}{2}\left(a_{n}+\frac{1}{a_{n}}\right) \cdots$ (1), we get $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) \cdots$ (2).
(1) + (2) gives
$$
S_{n}+S_{n-1}=\frac{1}{a_{n}}
$$

Also,
$$
S_{n}-S_{n-1}=a_{n} .
$$
Multiplying (3) and (4) gives $S_{n}^{2}-S_{n-1}^{2}=1$, so $\left\{S_{n}^{2}\right\}$ is an arithmetic sequence with the first term and common difference both being 1, hence $S_{n}^{2}=$ n. Therefore, $S_{n}=\sqrt{n}$. Thus, when $n>1$, $a_{n}=S_{n}-S_{n-1}=\sqrt{n}-\sqrt{n-1}$; when $n=1$, the above formula also holds, so $a_{n}=\sqrt{n}-\sqrt{n-1}$.