6. On the interval $\left[\frac{1}{2}, 2\right]$, the function $f(x)=x^{2}+p x+q$ and $g(x)=2 x+\frac{1}{x^{2}}$ achieve the same minimum value at the same point. The maximum value of $f(x)$ on $\left[\frac{1}{2}, 2\right]$ is $\qquad$ .
6. 4 .
$g(x)=x+x+\frac{1}{x^{2}} \geqslant 3$, when and only when $x=\frac{1}{x^{2}}$, i.e., $x=1 \in\left[\frac{1}{2}, 2\right]$, the equality holds. Thus, $f(x$ achieves its minimum value at the point $(1,3)$, then $f(x)=(x-1)^{2}+3, x \in\left[\frac{1}{2}, 2\right], f_{\max }=f(2)=4$.