How to find the domain of a solution for a differential equation? As an example, say I have the differential equation $xy' - 2y = x^2$ (I don't have an initial condition, sorry, but let's pretend there is one)
To find the integrating factor, I need to divide the equation by $x$, obtaining $y' - \frac{2}{x}y = x$
This is the part where I am confused, once I arrive at my solution equation, is there a domain to this, and is the domain $x > 0$ or $x < 0$ (depending on the initial condition)?
Also, is the domain a result of me dividing the equation by x when finding the integrating factor, since you can not divide an equation by 0, so $x$ must be greater than, or less than 0 (depending on the initial condition)?
Or do I only consider the differential equation that I started with at the very beginning, which was: $xy' - 2y = x^2$
In this equation, I do not see a value of x that would make the equation undefined, but I might be wrong, because if I set $\frac{dy}{dx}$ on one side of the equation, obtaining: $y' = \frac{x^2 + 2y}{x}$
then there is an $x$ in the denominator, which means $x$ can not be equal to 0?

Let's consider another example.
$\frac{dy}{dx} = \frac{y + 1}{x}$, where $f(-1) = 1$
From this equation, I can tell that $x$ can not equal 0.
But when I do separation of variables, I get: $\frac{1}{y+1} dy = \frac{1}{x} dx$
Does that mean in the solution, $y$ can not equal -1? But in the starting differential equation
( $\frac{dy}{dx} = \frac{y + 1}{x}$ ), $y+1$ was in the numerator, so $y$ could be equal to -1?

Are there any other things that I need to take into account of when finding the domain?
 A: Let us start with some preliminary analysis. In the equation $xy'(x)-2y(x)=x^2,$ what happens when $x=0,$ if we assume that $0$ is in the domain of $y$? You obtain that $0\cdot{y'(0)}-2\cdot{y(0)}=0.$ You may think that this forces $y(0)=0,$ because $0\cdot{y'(0)}-2\cdot{y(0)}=0-2\cdot{y(0)}=-2\cdot{y(0)}=0.$ However, this fails to take into account the possibility that $y$ is not differentiable at $0.$ In that case, we exclude $0$ from the domain of $y,$ and so the initial conditions must be given differently. So now we are assuming $xy'(x)-2y(x)=x^2$ holds for every nonzero $x.$ With that, you can show that the equation is equivalent to $$\frac{y'(x)}{x^2}-\frac{2y(x)}{x^3}=\frac1{x}.$$ Let $$z(x)=\frac{y(x)}{x^2},$$ hence $$z'(x)=\frac1{x}.$$ Since the domain is disjointed into two open intervals, two initial conditions are needed. The most convenient choice is to give $z(-1)=-y(-1)$ and $z(1)=y(1).$ Then $$\int_1^tz'(x)\,\mathrm{d}x=z(t)-z(1)=\ln(t),$$ while $$\int_{-1}^tz'(x)\,\mathrm{d}x=z(t)-z(-1)=\int_{-1}^t\frac1{x}\,\mathrm{d}x=\int_1^{-t}\frac1{x}\,\mathrm{d}x=\ln(-t),$$ implying $$z(x)=\begin{cases}z(1)+\ln(x)&x\gt0\\z(-1)+\ln(-x)&x\lt0\end{cases}.$$ Therefore, $$y(x)=\begin{cases}x^2[y(1)+\ln(x)]&x\gt0\\x^2[-y(-1)+\ln(-x)]&x\lt0\end{cases}.$$ As expected, the domain of the solution is $\mathbb{R}-\{0\},$ since $\ln(0)$ is not defined. Interestingly, $$y'(x)=\begin{cases}2x[y(1)+\ln(x)]+x&x\gt0\\2x[-y(-1)+\ln(-x)]+x&x\lt0\end{cases},$$ thus $$y''(x)=\begin{cases}2[y(1)+\ln(x)]+3&x\gt0\\2[-y(-1)+\ln(-x)]+3&x\lt0\end{cases}.$$ Why is this relevant? Because $y$ has a removable singularity at $0,$ so the singularity at $0$ can be removed. This is because $$\lim_{x\to0}y(x)=0.$$ This is also true for $y',$ as $$\lim_{x\to0}y'(x)=0.$$ However, the logarithmic singularity of $y''$ at $0$ is not removable, and so $y'$ is not differentiable at $0.$ This why we consider the solutions to the equation to not include $0$ in the domain.

Now to consider the second equation, $$y'(x)=\frac{y+1}{x}$$ with $y(-1)=1.$ This only determines the solutions for $x\lt0.$ With this in consideration, there are three cases to consider. One case is $y(x)=-1,$ which is already a solution, and the other case is when $y(x)\neq-1,$ in which case $$\frac{y'(x)}{y(x)+1}=\frac1{x},$$ and so $$\int_{-1}^t\frac{y'(x)}{y(x)+1}\,\mathrm{d}x=\ln\left[\frac{|y(t)+1|}2\right]=\int_{-1}^t\frac1{x}\,\mathrm{d}x=\ln(-t).$$ Therefore, $$\frac{|y(x)+1|}2=-x,$$ which means $$y(x)+1=2x$$ or $$y(x)+1=-2x.$$ $y$ can be analytically extended to all real numbers, but as a solution to the equation, it only has $(-\infty,0)$ as domain. The solution can be concisely given $$y(x)=-1+Ax,$$ with $A=-2,0,2.$
In general, if you have an equation $$f(x)y'(x)=g[y(x)],$$ then for those real numbers $r$ such that $g(r)=0,$ $y(x)=r$ as a constant function is a solution to the equation. The other solutions are given by $$f(x)\frac{y'(x)}{g[y(x)]}=1.$$ However, the solutions will have singularities for those real $q$ such that $f(q)=0.$
