To solve the integral
\[
I = \int \frac{x + 1}{(x^2 + x + 2)(x^2 + 4x + 5)} \, dx,
\]
we will use the method of partial fractions.
### Step 1: Factor the Denominator
First, we need to factor the denominator. The quadratic expressions \(x^2 + x + 2\) and \(x^2 + 4x + 5\) do not factor nicely over the reals, so we will use them as they are.
### Step 2: Set Up Partial Fractions
We can express the integrand as a sum of partial fractions:
\[
\frac{x + 1}{(x^2 + x + 2)(x^2 + 4x + 5)} = \frac{Ax + B}{x^2 + x + 2} + \frac{Cx + D}{x^2 + 4x + 5}
\]
where \(A\), \(B\), \(C\), and \(D\) are constants to be determined.
### Step 3: Combine the Right-Hand Side
Multiply both sides by the denominator \((x^2 + x + 2)(x^2 + 4x + 5)\):
\[
x + 1 = (Ax + B)(x^2 + 4x + 5) + (Cx + D)(x^2 + x + 2)
\]
### Step 4: Expand and Collect Like Terms
Expand the right-hand side:
\[
x + 1 = Ax^3 + 4Ax^2 + 5Ax + Bx^2 + 4Bx + 5B + Cx^3 + Cx^2 + 2Cx + Dx^2 + Dx + 2D
\]
Combine like terms:
\[
x + 1 = (A + C)x^3 + (4A + B + C + D)x^2 + (5A + 4B + 2C + D)x + (5B + 2D)
\]
### Step 5: Set Up the System of Equations
Now, we equate the coefficients from both sides:
1. \(A + C = 0\) (coefficient of \(x^3\))
2. \(4A + B + C + D = 0\) (coefficient of \(x^2\))
3. \(5A + 4B + 2C + D = 1\) (coefficient of \(x\))
4. \(5B + 2D = 1\) (constant term)
### Step 6: Solve the System of Equations
From equation 1, we can express \(C\) in terms of \(A\):
\[
C = -A
\]
Substituting \(C = -A\) into the other equations, we can solve for \(A\), \(B\), and \(D\):
1. Substitute into equation 2:
\[
4A + B - A + D = 0 \implies 3A + B + D = 0 \tag{5}
\]
2. Substitute into equation 3:
\[
5A + 4B - 2A + D = 1 \implies 3A + 4B + D = 1 \tag{6}
\]
3. Substitute into equation 4:
\[
5B + 2D = 1 \tag{7}
\]
Now we have a system of three equations (5, 6, and 7) to solve for \(A\), \(B\), and \(D\).
### Step 7: Solve for \(B\) and \(D\)
From equation (5), we can express \(D\) in terms of \(A\) and \(B\):
\[
D = -3A - B
\]
Substituting \(D\) into equation (7):
\[
5B + 2(-3A - B) = 1 \implies 5B - 6A - 2B = 1 \implies 3B - 6A = 1 \implies B = 2A + \frac{1}{3}
\]
Now substitute \(B\) back into equation (5) to find \(D\):
\[
D = -3A - (2A + \frac{1}{3}) = -5A - \frac{1}{3}
\]
### Step 8: Substitute Back to Find Constants
Now substitute \(B\) and \(D\) back into equation (6) to find \(A\):
\[
3A + 4(2A + \frac{1}{3}) + (-5A - \frac{1}{3}) = 1
\]
This simplifies to:
\[
3A + 8A + \frac{4}{3} - 5A - \frac{1}{3} = 1 \implies 6A + 1 = 1 \implies 6A = 0 \implies A = 0
\]
Substituting \(A = 0\) back gives \(C = 0\), \(B = \frac{1}{3}\), and \(D = -\frac{1}{3}\).
### Step 9: Write the Partial Fraction Decomposition
Now we can write:
\[
\frac{x + 1}{(x^2 + x + 2)(x^2 + 4x + 5)} = \frac{\frac{1}{3}}{x^2 + x + 2} + \frac{-\frac{1}{3}}{x^2 + 4x + 5}
\]
### Step 10: Integrate Each Term
Now we can integrate each term separately:
\[
I = \frac{1}{3} \int \frac{1}{x^2 + x + 2} \, dx - \frac{1}{3} \int \frac{1}{x^2 + 4x + 5} \, dx
\]
For the first integral, complete the square:
\[
x^2 + x + 2 = \left(x + \frac{1}{2}\right)^2 + \frac{7}{4}
\]
For the second integral:
\[
x^2 + 4x + 5 = (x + 2)^2 + 1
\]
### Step 11: Solve the Integrals
Using the formula \(\int \frac{1}{x^2 + a^2} \, dx = \frac{1}{a} \tan^{-1} \left(\frac{x}{a}\right) + C\):
1. For the first integral:
\[
\int \frac{1}{\left(x + \frac{1}{2}\right)^2 + \frac{7}{4}} \, dx = \frac{2}{\sqrt{7}} \tan^{-1} \left(\frac{2(x + \frac{1}{2})}{\sqrt{7}}\right)
\]
2. For the second integral:
\[
\int \frac{1}{(x + 2)^2 + 1} \, dx = \tan^{-1}(x + 2)
\]
### Final Solution
Combining these results, we get:
\[
I = \frac{1}{3} \cdot \frac{2}{\sqrt{7}} \tan^{-1} \left(\frac{2(x + \frac{1}{2})}{\sqrt{7}}\right) - \frac{1}{3} \tan^{-1}(x + 2) + C
\]