When playing around with DSolve, I enter the following:

  DSolve[{Derivative[1][y][x] == x + Abs[x]*y[x]}, y[x], x]

The output is:

$$y(x)\to e^{\frac{1}{2} (x \left| x\right| -1)} \int_1^x K[1] e^{\frac{1}{2} (1-K[1] \left| K[1]\right| )} \, dK[1]+c_1 e^{\frac{1}{2} (x \left| x\right| -1)}$$

I would have expected a conditional which accounts for $x \le 0$ and $x \gt 0$ or something along those lines.

How is one supposed to interpret the output that is being produced? Is it a bug or am I not reading it correctly?


Testing the solution numerically shows the solution appears to be valid:

{sol} = DSolve[{Derivative[1][y][x] == x + Abs[x]*y[x]}, y, x]

RandomReal[{-2, 2}, 10]
  C[1] = 1;
  Derivative[1][y][x] == x + Abs[x]*y[x] /.
    (sol /. Integrate -> NIntegrate) /. Abs' -> Sign],
 {x, %}]
  {0.609871, 0.532281, 0.731252, 0.265407, 1.74081, 1.90475,
   -1.04619, 0.550249, -1.59561, 0.582099}

  {True, True, True, True, True, True, True, True, True, True}

In response to Amzoti's comment, I'm not so sure about there being a nice solution, if x is assumed to be complex instead of real, which is how it is treated in Mathematica. If we specify that x is real, we do get a nice solution (and much more quickly):

Assuming[{x ∈ Reals},
  {sol} = DSolve[{Derivative[1][y][x] == x + Abs[x]*y[x]}, y, x]
y[x] /. sol // PiecewiseExpand

Mathematica graphics

  • $\begingroup$ It may be valid, but it is also quite ugly. A nice closed form solution without integrals is possible and that is how one would do it by hand. (+1) $\endgroup$ – Amzoti Feb 17 '15 at 13:51
  • $\begingroup$ @Amzoti Thanks. See update. $\endgroup$ – Michael E2 Feb 17 '15 at 14:00
  • $\begingroup$ That is what I would have expected and I forgot to take into account reals only, so thanks! I am surprised Mathematica does not respond that way by default with a statement, if $x \in \mathbb{R}$ or something along those lines. $\endgroup$ – Amzoti Feb 17 '15 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.