To evaluate the integral \(\int \frac{x^2 + x + 1}{x^2 - 1} \, dx\), we will follow these steps:
### Step 1: Polynomial Long Division
Since the degree of the numerator \(x^2 + x + 1\) is equal to the degree of the denominator \(x^2 - 1\), we perform polynomial long division.
1. Divide \(x^2 + x + 1\) by \(x^2 - 1\):
- The first term is \(1\) (since \(x^2 / x^2 = 1\)).
- Multiply \(1\) by \(x^2 - 1\) to get \(x^2 - 1\).
- Subtract:
\[
(x^2 + x + 1) - (x^2 - 1) = x + 2.
\]
So, we can rewrite the integral as:
\[
\int \left(1 + \frac{x + 2}{x^2 - 1}\right) \, dx.
\]
### Step 2: Separate the Integral
Now we can separate the integral:
\[
\int 1 \, dx + \int \frac{x + 2}{x^2 - 1} \, dx.
\]
### Step 3: Evaluate the First Integral
The first integral is straightforward:
\[
\int 1 \, dx = x.
\]
### Step 4: Evaluate the Second Integral
Now we need to evaluate \(\int \frac{x + 2}{x^2 - 1} \, dx\). We can split this into two parts:
\[
\int \frac{x}{x^2 - 1} \, dx + \int \frac{2}{x^2 - 1} \, dx.
\]
#### Step 4.1: Evaluate \(\int \frac{x}{x^2 - 1} \, dx\)
For \(\int \frac{x}{x^2 - 1} \, dx\), we can use substitution:
Let \(t = x^2 - 1\), then \(dt = 2x \, dx\) or \(\frac{dt}{2} = x \, dx\).
Thus, we have:
\[
\int \frac{x}{x^2 - 1} \, dx = \frac{1}{2} \int \frac{1}{t} \, dt = \frac{1}{2} \ln |t| + C = \frac{1}{2} \ln |x^2 - 1| + C.
\]
#### Step 4.2: Evaluate \(\int \frac{2}{x^2 - 1} \, dx\)
For \(\int \frac{2}{x^2 - 1} \, dx\), we can use partial fraction decomposition:
\[
\frac{2}{x^2 - 1} = \frac{2}{(x - 1)(x + 1)} = \frac{A}{x - 1} + \frac{B}{x + 1}.
\]
Multiplying through by \(x^2 - 1\) gives:
\[
2 = A(x + 1) + B(x - 1).
\]
Setting \(x = 1\) gives \(2 = 2A \Rightarrow A = 1\).
Setting \(x = -1\) gives \(2 = -2B \Rightarrow B = -1\).
So, we have:
\[
\frac{2}{x^2 - 1} = \frac{1}{x - 1} - \frac{1}{x + 1}.
\]
Thus,
\[
\int \frac{2}{x^2 - 1} \, dx = \int \left(\frac{1}{x - 1} - \frac{1}{x + 1}\right) \, dx = \ln |x - 1| - \ln |x + 1| + C = \ln \left|\frac{x - 1}{x + 1}\right| + C.
\]
### Step 5: Combine All Parts
Now we combine all parts:
\[
\int \frac{x^2 + x + 1}{x^2 - 1} \, dx = x + \frac{1}{2} \ln |x^2 - 1| + \ln \left|\frac{x - 1}{x + 1}\right| + C.
\]
### Final Answer
Thus, the final answer is:
\[
\int \frac{x^2 + x + 1}{x^2 - 1} \, dx = x + \frac{1}{2} \ln |x^2 - 1| + \ln \left|\frac{x - 1}{x + 1}\right| + C.
\]