1
$\begingroup$

I'm trying to simulate a water tank. The dynamic of the system should be described by:

DSolve[{y'[x] == Piecewise[{{-Sqrt[y[x]], 0 < y[x]}}, 0.], y[0] == 10}, y[x], x]

Blockquote

An infinite object ComplexInfinity might occur if you look at the -Sqrt[y[x]] term outside of 0 < y[x], however that branch should never be active under this condition.

enter image description here

So i don't under stand why Mathematica looks at those branches of the general solution where it is unable to compute the limit at the given points.

EDIT: Imposing the real number constraint gives the same solution as Daniel Huber however this solution stops when tank is empty. I want the solution to be Piecewise[{{1/4 (40 - 4 Sqrt[10] x + x^2), x < 2*Sqrt[10]}}, 0].

How can i convince Mathematica to solve this problem in a way that gives me a constant solution after the water ran out of tank?

( I'm running Mathematika 11.3 )

$\endgroup$

1 Answer 1

1
$\begingroup$

Remember, if not told otherwise, MMA assumes all variables to be complex. You have to specify that x is real and >=0:

DSolve[{y'[x] == Piecewise[{{-Sqrt[y[x]], 0 < y[x]}}, 0.], 
  y[0] == 10}, y[x], x, Assumptions -> {x >= 0}]

With this you get:

enter image description here

$\endgroup$
1
  • $\begingroup$ This note about assuming complexity is helpful, however i would want a solution that has constant 0 after 2Sqrt[10] Mathematica seems to solve one branch and then not continue. The correct solution to the differential equation should be Piecewise[{{1/4 (40 - 4 Sqrt[10] x + x^2), x < 2*Sqrt[10]}}, 0] $\endgroup$ Commented Mar 16, 2021 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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