To solve the given differential equation \( x \, dy = (y + x^3 \cos x) \, dx \) with the initial condition \( f(\pi) = 0 \), we will follow these steps:
### Step 1: Rearranging the equation
We start with the given equation:
\[
x \, dy = (y + x^3 \cos x) \, dx
\]
Rearranging gives:
\[
x \, dy - y \, dx = x^3 \cos x \, dx
\]
### Step 2: Dividing by \( x^2 \)
Next, we divide both sides by \( x^2 \):
\[
\frac{dy}{x} - \frac{y}{x^2} \, dx = x \cos x \, dx
\]
### Step 3: Recognizing the left side as a derivative
The left side can be recognized as the derivative of \( \frac{y}{x} \):
\[
d\left(\frac{y}{x}\right) = x \cos x \, dx
\]
### Step 4: Integrating both sides
Now we integrate both sides:
\[
\int d\left(\frac{y}{x}\right) = \int x \cos x \, dx
\]
The right side can be integrated using integration by parts. Let:
- \( u = x \) and \( dv = \cos x \, dx \)
Then,
- \( du = dx \) and \( v = \sin x \)
Using integration by parts:
\[
\int x \cos x \, dx = x \sin x - \int \sin x \, dx = x \sin x + \cos x + C
\]
### Step 5: Equating the integrals
Thus, we have:
\[
\frac{y}{x} = x \sin x + \cos x + C
\]
Multiplying through by \( x \):
\[
y = x^2 \sin x + x \cos x + Cx
\]
### Step 6: Applying the initial condition
We know \( f(\pi) = 0 \):
\[
0 = \pi^2 \sin \pi + \pi \cos \pi + C\pi
\]
Since \( \sin \pi = 0 \) and \( \cos \pi = -1 \):
\[
0 = 0 - \pi + C\pi \implies C\pi = \pi \implies C = 1
\]
### Step 7: Final solution for \( y \)
Substituting \( C \) back into the equation:
\[
y = x^2 \sin x + x \cos x + x
\]
### Step 8: Finding \( f\left(\frac{\pi}{2}\right) \)
Now we need to find \( f\left(\frac{\pi}{2}\right) \):
\[
f\left(\frac{\pi}{2}\right) = \left(\frac{\pi}{2}\right)^2 \sin\left(\frac{\pi}{2}\right) + \left(\frac{\pi}{2}\right) \cos\left(\frac{\pi}{2}\right) + \frac{\pi}{2}
\]
Calculating this:
\[
= \frac{\pi^2}{4} \cdot 1 + \frac{\pi}{2} \cdot 0 + \frac{\pi}{2} = \frac{\pi^2}{4} + \frac{\pi}{2}
\]
Thus, the final answer is:
\[
f\left(\frac{\pi}{2}\right) = \frac{\pi^2}{4} + \frac{\pi}{2}
\]