To solve the integral \( I = \int \frac{x^2 e^x}{(x+2)^2} \, dx \), we can follow these steps:
### Step 1: Rewrite the Integral
We start by rewriting the integral \( I \):
\[
I = \int \frac{x^2 e^x}{(x+2)^2} \, dx
\]
We can add and subtract 4 in the numerator:
\[
I = \int \frac{x^2 - 4 + 4}{(x+2)^2} e^x \, dx
\]
This simplifies to:
\[
I = \int \frac{(x^2 - 4) + 4}{(x+2)^2} e^x \, dx
\]
### Step 2: Factor the Numerator
Notice that \( x^2 - 4 \) can be factored as:
\[
x^2 - 4 = (x-2)(x+2)
\]
Thus, we can rewrite the integral:
\[
I = \int \frac{(x-2)(x+2) + 4}{(x+2)^2} e^x \, dx
\]
### Step 3: Separate the Integral
Now we can separate the terms in the integral:
\[
I = \int \left( \frac{x-2}{x+2} + \frac{4}{(x+2)^2} \right) e^x \, dx
\]
### Step 4: Simplify the Integral
This gives us two separate integrals:
\[
I = \int \frac{x-2}{x+2} e^x \, dx + \int \frac{4}{(x+2)^2} e^x \, dx
\]
### Step 5: Solve the First Integral
For the first integral, we can use integration by parts. Let:
- \( u = \frac{x-2}{x+2} \) and \( dv = e^x \, dx \)
Then, we find \( du \) and \( v \):
\[
du = \frac{(x+2)(1) - (x-2)(1)}{(x+2)^2} \, dx = \frac{4}{(x+2)^2} \, dx
\]
\[
v = e^x
\]
Using integration by parts:
\[
\int u \, dv = uv - \int v \, du
\]
This gives us:
\[
\int \frac{x-2}{x+2} e^x \, dx = \frac{x-2}{x+2} e^x - \int e^x \cdot \frac{4}{(x+2)^2} \, dx
\]
### Step 6: Combine the Integrals
Now we can combine the results:
\[
I = \left( \frac{x-2}{x+2} e^x - \int \frac{4 e^x}{(x+2)^2} \, dx \right) + \int \frac{4 e^x}{(x+2)^2} \, dx
\]
The integrals of \( \frac{4 e^x}{(x+2)^2} \) cancel out, leading to:
\[
I = \frac{x-2}{x+2} e^x + C
\]
### Final Answer
Thus, the final answer is:
\[
I = \frac{x-2}{x+2} e^x + C
\]