Example 8 Given $f(x)=a_{1} x+a_{2} x^{2}+a_{3} x^{3}+\cdots+a_{n} x^{n}$, and $a_{1}, a_{2}, a_{3}, \cdots, a_{n}$ form an arithmetic sequence, $n$ is a positive even number. Also, $f(1)=n^{2}, f(-1)=n$. Try to compare $f\left(\frac{1}{2}\right)$ with 3.
Solution: Since $f(1)=a_{1}+a_{2}+\cdots+a_{n}=n^{2}$, we have $\frac{\left(a_{1}+a_{n}\right) n}{2}=n^{2}$, which means $a_{1}+a_{n}=2 n$.
Also, $f(-1)=-a_{1}+a_{2}-a_{3}+a_{4}-a_{5}+\cdots-a_{n-1}+a_{n}=n$.
That is, $\left(a_{2}-a_{1}\right)+\left(a_{4}-a_{3}\right)+\cdots+\left(a_{n}-a_{n-1}\right)=n$.
So $\frac{n}{2} d=n$, which means $d=2$.
From $a_{1}+a_{n}=2 a_{1}+2(n-1)=2 n$, we get $2 a_{1}-2+2 n=2 n$, hence $a_{1}=1, a_{n}=a_{1}+2(n-1)=2 n-1(n \in \mathbf{N})$.
Therefore, $f(x)=x+3 x^{2}+5 x^{3}+\cdots+(2 n-1) x^{n}$.
Thus, $f\left(\frac{1}{2}\right)=\frac{1}{2}+3\left(\frac{1}{2}\right)^{2}+5\left(\frac{1}{2}\right)^{3}+\cdots+(2 n-1)\left(\frac{1}{2}\right)^{n}$,
$$
\frac{1}{2} f\left(\frac{1}{2}\right)=\left(\frac{1}{2}\right)^{2}+3\left(\frac{1}{2}\right)^{3}+\cdots+(2 n-1)\left(\frac{1}{2}\right)^{n+1} \text {. }
$$

Subtracting the above two equations, we get
$$
\frac{1}{2} f\left(\frac{1}{2}\right)=\frac{1}{2}+2\left(\frac{1}{2}\right)^{2}+2\left(\frac{1}{2}\right)^{3}+\cdots+2\left(\frac{1}{2}\right)^{n}-(2 n-1)\left(\frac{1}{2}\right)^{n+1} \text {. }
$$

That is, $\frac{1}{2} f\left(\frac{1}{2}\right)=\frac{1}{2}+\frac{1}{2}+\left(\frac{1}{2}\right)^{2}+\cdots+\left(\frac{1}{2}\right)^{n-1}-(2 n-1)\left(\frac{1}{2}\right)^{n+1}$.
Thus, $f\left(\frac{1}{2}\right)=1+1+\frac{1}{2}+\cdots+\left(\frac{1}{2}\right)^{n-2}-(2 n-1)\left(\frac{1}{2}\right)^{n}$
$$
=1+\frac{1-\left(\frac{1}{2}\right)^{n-1}}{1-\frac{1}{2}}-(2 n-1)\left(\frac{1}{2}\right)^{n} .
$$

Therefore, $f\left(\frac{1}{2}\right)=3-\left(\frac{1}{2}\right)^{n-2}-(2 n-1)\left(\frac{1}{2}\right)^{n}<3$, which means $f\left(\frac{1}{2}\right)<3$.
Analysis: From the given conditions, we find $a_{n}=2 n-1, f\left(\frac{1}{2}\right)$ is the sum of the first $n$ terms of the sequence $\left\{(2 n-1) x^{n}\right\}$, which is formed by the product of the corresponding terms of the arithmetic sequence $\{2 n-1\}$ and the geometric sequence $\left\{x^{n}\right\}$. For the problem of finding the sum of the first $n$ terms of such a sequence, we usually use the method of wrong-term subtraction. In addition, there are other methods for finding the sum of the first $n$ terms of a sequence, such as reverse addition, splitting and cancellation, and grouping summation.