Solving $y+xy'=a(1+xy)\;\;,\;\; y(\frac 1a)=-a$

Solve$$y+xy'=a(1+xy)\;\;,\;\; y(\frac 1a)=-a$$

I used the substitution $u=1+xy\;\;\Rightarrow\;\; u'=y+xy'$ . And the equation becomes,

$$u'=au\;\;\Rightarrow \;\; \frac{du}u=a\;dx \;\;\Rightarrow \ln|u|=ax+C$$ Hence the solution is $\ln|1+xy|=ax+C.$ But when I substitute $x=\frac 1a$ and $y=-a$ In order to find $C$, LHS of the equation becomes $\ln|0|$ and zero doesn't belong to domain of logarithm. How can I fix the issue?


Well, it is not hard to see that we rewrite your DE in the following form:

$$\text{y}'\left(x\right)+\frac{\left(1-\text{a}x\right)\text{y}\left(x\right)}{x}=\frac{\text{a}}{x}\tag1$$

Now, let:

$$\mu\left(x\right):=\exp\left\{\int\frac{1-\text{a}x}{x}\space\text{d}x\right\}=x\exp\left(-\text{a}x\right)\tag2$$

When we multiply both sides by $\mu\left(x\right)$, use the fact that $\exp\left(-\text{a}x\right)\left(1-\text{a}x\right)=\frac{\text{d}}{\text{d}x}\left(x\exp\left(-\text{a}x\right)\right)$ and apply the reverse product rule we end up with:

$$\frac{\text{d}}{\text{d}x}\left(x\exp\left(-\text{a}x\right)\text{y}\left(x\right)\right)=\text{a}\exp\left(-\text{a}x\right)\tag3$$

Integrate both sides with respect to $x$:

$$x\exp\left(-\text{a}x\right)\text{y}\left(x\right)=\text{C}-\exp\left(-\text{a}x\right)\tag4$$

Dividing both sides by $\mu\left(x\right)$:

$$\text{y}\left(x\right)=\frac{\text{C}\exp\left(\text{a}x\right)-1}{x}\tag5$$

So, we can solve for $\text{C}$:

$$\text{y}\left(\frac{1}{\text{a}}\right)=\frac{\text{C}\exp\left(\text{a}\cdot\frac{1}{\text{a}}\right)-1}{\frac{1}{\text{a}}}=\text{a}\left(\text{C}e-1\right)=-\text{a}\space\Longleftrightarrow\space\text{C}=\frac{2}{e}\tag6$$

So, we end up with:

$$\text{y}\left(x\right)=\frac{\frac{2}{e}\cdot\exp\left(\text{a}x\right)-1}{x}=\frac{2\exp\left(\text{a}x\right)-e}{ex}=\frac{2\exp\left(\text{a}x\right)}{ex}-\frac{1}{x}\tag7$$