You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using solve to solve a Piecewise equation where the solutions mat or may not exist depending on a parameter of the equation leads to nan results:
In [9]: eq2 =Piecewise((x, Ne(y, 0)), (x+1, True))
In [10]: eq2
Out[10]:
⎧ x for y ≠0
⎨
⎩x +1 otherwise
In [11]:solve(eq2, x)
Out[11]:
⎡⎧-1for y =0 ⎧ 0for y ≠0⎤
⎢⎨ , ⎨ ⎥
⎣⎩nan otherwise ⎩nan otherwise⎦
In principle those could be combined to give something like
In [15]:Piecewise((-1, Eq(y, 0)), (0, True))
Out[15]:
⎧-1for y =0
⎨
⎩0 otherwise
However in general that can't work because the number of solutions might be different for different cases e.g.:
In [12]: eq2 =Piecewise((x, Ne(y, 0)), (x**2-1, True))
In [13]: eq2
Out[13]:
⎧ x for y ≠0
⎪
⎨ 2
⎪x -1 otherwise
⎩
In [14]:solve(eq2, x)
Out[14]:
⎡⎧-1for y =0 ⎧ 0for y ≠0 ⎧ 1for y =0⎤
⎢⎨ , ⎨ , ⎨ ⎥
⎣⎩nan otherwise ⎩nan otherwise ⎩nan otherwise⎦
When there are no Piecewise then solve returns solutions for generic parameter values e.g.:
In [16]:solve(y*x -1, x)
Out[16]:
⎡1⎤
⎢─⎥
⎣y⎦
In this case the solution exists only if y is non-zero. Following the same reasoning solve should discard all Eq(...) cases in a Piecewise to include only cases that hold for generic values of the parameters.
It would be good to represent solution sets that are conditional on the parameter values but it is not clear how that could be done within the solve API. I suppose that the above nan results are an attempt to guard against incorrect solutions but it doesn't seem like a very useful approach. We should in any case document what the expected behaviour should be.
The same issue affects solveset and nonlinsolve:
In [23]: eq2 =Piecewise((x, Ne(y, 0)), (x**2-1, True))
In [24]: eq2
Out[24]:
⎧ x for y ≠0
⎪
⎨ 2
⎪x -1 otherwise
⎩
In [25]:solveset(eq2, x)
Out[25]: ∅
In [26]: eq3 =Piecewise((x, Eq(y, 0)), (x**2-1, True))
In [27]: eq3
Out[27]:
⎧ x for y =0
⎪
⎨ 2
⎪x -1 otherwise
⎩
In [28]:solveset(eq3, x)
Out[28]: {-1, 0, 1}
The text was updated successfully, but these errors were encountered:
Using
solve
to solve aPiecewise
equation where the solutions mat or may not exist depending on a parameter of the equation leads to nan results:In principle those could be combined to give something like
However in general that can't work because the number of solutions might be different for different cases e.g.:
When there are no Piecewise then solve returns solutions for generic parameter values e.g.:
In this case the solution exists only if
y
is non-zero. Following the same reasoningsolve
should discard allEq(...)
cases in a Piecewise to include only cases that hold for generic values of the parameters.It would be good to represent solution sets that are conditional on the parameter values but it is not clear how that could be done within the solve API. I suppose that the above nan results are an attempt to guard against incorrect solutions but it doesn't seem like a very useful approach. We should in any case document what the expected behaviour should be.
The same issue affects
solveset
andnonlinsolve
:The text was updated successfully, but these errors were encountered: