To evaluate the integral \(\int \frac{x^3 - 2x + 1}{x^2 + 1} \, dx\), we can use polynomial long division to simplify the integrand, if necessary, and then apply standard integration techniques.
First, let's perform polynomial long division on \(\frac{x^3 - 2x + 1}{x^2 + 1}\):
1. Divide \(x^3\) by \(x^2\), which gives \(x\).
2. Multiply \(x\) by \(x^2 + 1\), which gives \(x^3 + x\).
3. Subtract \(x^3 + x\) from \(x^3 - 2x + 1\), which gives \(-3x + 1\).
So,
\[
\frac{x^3 - 2x + 1}{x^2 + 1} = x + \frac{-3x + 1}{x^2 + 1}
\]
Now, we can split the integral:
\[
\int \frac{x^3 - 2x + 1}{x^2 + 1} \, dx = \int \left( x + \frac{-3x + 1}{x^2 + 1} \right) \, dx
\]
This gives us two separate integrals:
\[
\int x \, dx + \int \frac{-3x + 1}{x^2 + 1} \, dx
\]
1. The first integral is straightforward:
\[
\int x \, dx = \frac{x^2}{2}
\]
2. For the second integral, we can split it further:
\[
\int \frac{-3x + 1}{x^2 + 1} \, dx = -3 \int \frac{x}{x^2 + 1} \, dx + \int \frac{1}{x^2 + 1} \, dx
\]
The first part of the second integral can be solved using the substitution \( u = x^2 + 1 \):
\[
du = 2x \, dx \Rightarrow \frac{1}{2} du = x \, dx
\]
\[
-3 \int \frac{x}{x^2 + 1} \, dx = -3 \int \frac{1}{2} \frac{du}{u} = -\frac{3}{2} \ln |u| = -\frac{3}{2} \ln (x^2 + 1)
\]
The second part is a standard integral:
\[
\int \frac{1}{x^2 + 1} \, dx = \arctan(x)
\]
Combining everything, we get:
\[
\int \frac{x^3 - 2x + 1}{x^2 + 1} \, dx = \frac{x^2}{2} - \frac{3}{2} \ln (x^2 + 1) + \arctan(x) + C
\]
So the final answer is:
\[
\boxed{\frac{x^2}{2} - \frac{3}{2} \ln (x^2 + 1) + \arctan(x) + C}
\]