Is it necessary to consider absolute values when solving the differential equation $\frac{dy}{dx}-\frac{1}{x}y=1$

ordinary differential equations

Given the differential equation $$\frac{dy}{dx}-\frac{1}{x}y=1$$ I'd like to solve it and understand where I should use absolute value functions and why or why not. This is a problem from MIT OCW's 18.03SC Differential Equations, and in their solutions they don't make any considerations for absolute values when integrating $x^{-1}$ in solving this differential equation.

Edit: I failed to specify that the MIT OCW problem also specifies an initial value y(1)=7. I now think that perhaps they disregard negative x because the solution with this initial value will be the one with non-negative x, ie the solution to the right of the singularity at x=0.

First, I find an integrating factor
$$u(x)=e^{-\int x^{-1} dx}=e^{-\ln |x|}=|x|^{-1}$$

Then I multiply the differential equation by the integrating factor
$$|x|^{-1}\frac{dy}{dx}-|x|^{-1}x^{-1}y=|x|^{-1}$$

This is where the absolute value starts to become important.
$$\frac{d}{dx}(|x|^{-1}y)=|x|^{-1}$$
We can take the latter step because if we have $f(x)=|x|^{-1}$ then
$$f'(x)=\begin{cases}
-x^{-2} \ \ x\geq 0\\
x^{-2}\ \ x\leq 0\\
\end{cases}=-\frac{1}{x|x|}$$

$$|x|^{-1}y=\int |x|^{-1}dx+C$$

For the next step I will use that
$$\int |x|^{-1}dx=\begin{cases}
\int x^{-1}dx = \ln(x)\ \ x \geq 0 \\
– \int x^{-1} = -\ln(|x|)=-\ln(-x)\ \ x \leq 0 \\
\end{cases}$$

So
$$y(x)=\begin{cases}
x \ln(x) +cx\ \ x \geq 0 \\
x \ln(-x)-cx\ \ x \leq 0 \\
\end{cases}$$

In the case of the official solution to this problem the integrating factor is simply $x^{-1}$ and so the solution is just $y(x)=x \ln(x) +cx$, the same solution I have but in my case that solution is only valid for non-negative x.

Which answer is the inaccurate one?

Best Answer

If we do it your way and multiply by $|x|$, note that $|x|$ is equal to $x$ or $-x$ depending on the sign of $x$. If it's equal to $x$, we simply obtain their equation. And if it's equal to $-x$, we can just multiply our equation by $-1$ on both sides, and obtain their equation again.

The important thing here is that $\frac{d}{dx}(x^{-1}y) = x^{-1} \frac{dy}{dx} - x^{-2} y$, and it's this expression that we want to obtain on the left-hand side, so that we can integrate both sides. And we obtain it by multiplying the original ODE by $x^{-1}$. So $x^{-1}$ is an integrating factor, and once we found it, who cares how we found it? We may not even need to tell anyone how we did it. (So in this case one can justify being slightly sloppy when integrating $1/x$, but you're right that one should in general be more careful. And in general, one should not omit the constant of integration either, like both you and they did! But here one gets away with doing that as well, for exactly the same reason: if we include it, the whole equation just gets multiplied by the nonzero factor $e^C$, which makes no difference.)

Another remark is that the ODE is singular at $x=0$, so the maximal interval of existence for an initial value problem is either going to be $x>0$ or $x<0$ anyway, depending on whether the initial data is given at $x_0>0$ or at $x_0<0$ (as you noted). This means that if you want write a formula for the general solution on the set $x \neq 0$, like at the end of your answer, the constant $c$ need not be the same in the two cases, and it would perhaps be more precise to write $C_1$ and $C_2$ instead. But usually this is left understood, and most people would simply write $y(x)=x \ln|x|+C x$. (This is just like writing $\int \frac{dx}{x} = \ln|x|+C$, as everyone does, where it is should actually be $\ln|x| + C(x)$ where $C(x)$ is a locally constant function, equal to $C_1$ for $x>0$ and to $C_2$ for $x<0$.)

Related Question