4.38. Integrate the equation $\frac{d y}{d x}+x y=x^{2}$ using two methods: the method of variation of arbitrary constant and the Bernoulli method.
Solution. 1st method. Apply the method of variation of arbitrary constant.

1st step. Solve the corresponding homogeneous equation $\frac{d y}{d x}+x y=0$ by the method of separation of variables:

$$
\frac{d y}{y}=-x d x ; \int \frac{d y}{y}=-\int x d x ; \ln |y|=-\ln |x|+\ln C ; \quad y(x)=\frac{C}{x}
$$

2nd step. Replace the arbitrary constant of integration $C$ with a function $C(x)$ to be determined:

$$
y(x)=\frac{C(x)}{x}
$$

3rd step. Substitute the new expression for $y(x)$ into the original equation and obtain an equation for $C(x)$:

$$
\frac{d C}{d x} \cdot \frac{1}{x}-x \frac{C(x)}{x} e^{-\int p(x) d x}+x \frac{C(x)}{x} \cdot e^{-\int p(x) d x}=x^{2}
$$

from which $\frac{d C}{d x}=x^{3}$.

4th step. Solve the obtained equation by the method of separation of variables: $d C=x^{3} d x$;

$$
\int d C=\int x^{3} d x ; \quad C(x)=\frac{x^{4}}{4}+C_{1}
$$

5th step. Write the final answer:

$$
y(x)=\left(\frac{x^{4}}{4} x+C_{1}\right) \frac{1}{x}=\frac{x^{3}}{4}+\frac{C_{1}}{x}
$$

2nd method. Apply the Bernoulli method.

1st step. Represent the unknown function $y(x)$ as a product of two new unknown functions $u(x)$ and $v(x)$:

$$
y(x)=u(x) \cdot v(x), \text { with } \frac{d y}{d x}=v(x) \frac{d u}{d x}+u(x) \frac{d v}{d x} \text {. }
$$

2nd step. Substitute the expressions for $y(x)$ and its derivative into the original equation:

$$
v(x) \frac{d u}{d x}+u(x) \frac{d v}{d x}+x u(x) v(x)=x^{2}
$$

and factor out $u(x)$ in the last two terms of the left side: $v(x) \frac{d u}{d x}+u(x)\left[\frac{d v}{d x}+x v(x)\right]=x^{2}$.

3rd step. Set the expression in the square brackets to zero: $\frac{d v}{d x}+x v(x)=0$, and solve the obtained equation by the method of separation of variables: $v(x)=\frac{1}{x}$. Here, the arbitrary constant of integration is not written.

4th step. Substitute the found function into the equation obtained in the 2nd step, to get an equation for the unknown function $u(x): \frac{1}{x} \cdot \frac{d u}{d x}=x^{2}$. Solve it by the method of separation of variables: $d u=x^{3} d x ; u(x)=\frac{x^{4}}{4}+C$. Note that on this step, the arbitrary constant of integration is written.

5th step. Write the answer:

$$
y(x)=\left(\frac{x^{4}}{4}+C\right) \cdot \frac{1}{x}=\frac{x^{3}}{4}+\frac{C}{x}
$$