-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NotImplementedError: Unable to find critical points for Abs(f(x)) #21956
Comments
If you define Here, one could think that the code would replace your However, your observation should be relevant in addition to that. |
An example where your observation is useful is Although
gives The function |
Here the function is differentiated: Line 193 in a63cb72
Depending on whether x has real assumptions different results are obtained: In [2]: x = Symbol('x')
In [3]: Abs(x**3).diff(x)
Out[3]:
⎛⎛ 2 3 ⎞ ⎛ 2 d d 2 d ⎞ ⎛ 3 2 ⎞ ⎛ 2 d
⎜⎝3⋅re (x)⋅im(x) - im (x)⎠⋅⎜3⋅re (x)⋅──(im(x)) + 6⋅re(x)⋅im(x)⋅──(re(x)) - 3⋅im (x)⋅──(im(x))⎟ + ⎝re (x) - 3⋅re(x)⋅im (x)⎠⋅⎜3⋅re (x)⋅──(re(x)) - 6⋅re(x)⋅im(
⎝ ⎝ dx dx dx ⎠ ⎝ dx
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
3
x
d 2 d ⎞⎞ ⎛ 3⎞
x)⋅──(im(x)) - 3⋅im (x)⋅──(re(x))⎟⎟⋅sign⎝x ⎠
dx dx ⎠⎠
────────────────────────────────────────────
In [4]: x = Symbol('x', real=True)
In [5]: Abs(x**3).diff(x)
Out[5]:
2
x ⋅sign(x) + 2⋅x⋅│x│ Without the real assumption we get: In [6]: x = Symbol('x')
In [7]: solveset(Abs(x**3).diff(x), x, Reals)
Out[7]:
⎧ │ ⎛ 2 d ⎞⎫ ⎧ │ ⎛ 2 d ⎞⎫
{0} ∪ ⎨x │ x ∊ (-∞, 0) ∧ ⎜x ⋅──(x) = 0⎟⎬ ∪ ⎨x │ x ∊ (0, ∞) ∧ ⎜x ⋅──(x) = 0⎟⎬
⎩ │ ⎝ dx ⎠⎭ ⎩ │ ⎝ dx ⎠⎭
In [8]: solveset(Abs(x**3).diff(x), x, Interval(0, 3))
Out[8]:
⎧ │ ⎛ 2 d ⎞⎫
{0} ∪ ⎨x │ x ∊ (0, 3] ∧ ⎜x ⋅──(x) = 0⎟⎬
⎩ │ ⎝ dx ⎠⎭
In [9]: _.doit()
Out[9]:
⎧ │ ⎛ 2 ⎞⎫
{0} ∪ ⎨x │ x ∊ (0, 3] ∧ ⎝x = 0⎠⎬
⎩ │ ⎭ I think it should be possible to resolve that ConditionSet further. |
Can I get this? |
It would be particularly useful to some of my projects if it were possible for me to find the maximum of the absolute value of a single variable function. Here is a reproducible example:
I've noted that max(|f|) = max(|min(f)|, |max(f)|) is a useful simplification that can be implemented explicitly.
As a feature request, it would be beneficial if SymPy did this (or something better) automatically.
The text was updated successfully, but these errors were encountered: