We are given the integral $\int\left(\sqrt{x}-\frac{1}{\sqrt{x}}\right)^{2} d x$.
First,expand the square using the algebraic identity $(a-b)^{2} = a^{2} + b^{2} - 2ab$:
$\left(\sqrt{x}-\frac{1}{\sqrt{x}}\right)^{2} = (\sqrt{x})^{2} + \left(\frac{1}{\sqrt{x}}\right)^{2} - 2(\sqrt{x})\left(\frac{1}{\sqrt{x}}\right) = x + \frac{1}{x} - 2$.
Now,substitute this back into the integral:
$\int\left(x+\frac{1}{x}-2\right) d x$.
Using the linearity property of integrals,we can split this into three separate integrals:
$\int x \, d x + \int \frac{1}{x} \, d x - 2 \int 1 \, d x$.
Integrating each term:
$\int x \, d x = \frac{x^{2}}{2}$,
$\int \frac{1}{x} \, d x = \log |x|$,
$-2 \int 1 \, d x = -2x$.
Combining these results and adding the constant of integration $C$:
$\frac{x^{2}}{2} + \log |x| - 2x + C$,where $C$ is an arbitrary constant.