3. Given that the function $f(x)$ is defined and decreasing on $(-\infty, 3]$, and for $x \in \mathbf{R}, f\left(a^{2}-\sin x\right) \leqslant f(a+1+$ $\cos ^{2} x$ ) always holds, then the range of real number $a$ is $\qquad$
3. $\left[-\sqrt{2}, \frac{1-\sqrt{10}}{2}\right]$.

Solution: From the given, we have $a+1+\cos ^{2} x \leqslant a^{2}-\sin x \leqslant 3$ for $x \in \mathbf{R}$.
That is, $\left\{\begin{array}{l}a^{2} \leqslant 3+\sin x \\ a^{2}-a \geqslant 1+\cos ^{2} x+\sin x\end{array}\right.$ for $x \in \mathbf{R}$.
If $a^{2} \leqslant 3+\sin x$ for $x \in \mathbf{R}$.
Then we have $a^{2} \leqslant(3+\sin x)_{\text {min }}=2$.
Solving this, we get $-\sqrt{2} \leqslant a \leqslant \sqrt{2}$.
If $a^{2}-a \geqslant 1+\cos ^{2} x+\sin x=-\left(\sin x-\frac{1}{2}\right)+$ $\frac{9}{4}$ for $x \in \mathbf{R}$.

Then we have $a^{2}-a \geqslant-\left[\left(\sin x-\frac{1}{2}\right)^{2}+\frac{9}{4}\right]_{\max }=\frac{9}{4}$, solving this, we get $a \leqslant \frac{1-\sqrt{10}}{2}$ or $a \geqslant \frac{1+\sqrt{10}}{2}$.
Therefore, the range of real number $a$ is $\left[-\sqrt{2}, \frac{1-\sqrt{10}}{2}\right]$.