Re: [sympy] 'no ordering relation is defined for complex numbers' when plotting function involving Max

146 views
Skip to first unread message

Aaron Meurer

unread,
Jan 12, 2013, 2:45:40 PM1/12/13
to sy...@googlegroups.com
First off, why do you use Lambda. Just use Max(x, 5).

This is definitely a bug. You can work around it by wrapping x in
re(), like plot(Max(re(x), 5)). Perhaps plot should automatically do
this if x is assumed to be real. Even so, it should not have this
error regardless of assumptions.

Aaron Meurer

On Sat, Jan 12, 2013 at 11:53 AM, Andre Holzner <andre....@gmail.com> wrote:
> Dear sympy experts,
>
> I tried to plot a 'ramp function' as follows (sympy 0.7.2 on OSX):
>
> from sympy import *
> x = Symbol('x',real = True)
> f = Lambda(x, Max(x,5))
> plot(f(x), (x,0,10))
>
> but I get the exception shown below on the last line. Should I be doing this
> differently ?
> When evaluating the function f at some values, it looks like it is returning
> the correct values.
>
> best regards,
>
> Andre
>
> stack trace:
>
> Traceback (most recent call last):
> File "/tmp/test.py", line 6, in <module>
> plot(f(x), (x,0,10))
> File
> "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/plotting/plot.py",
> line 1165, in plot
> plots.show()
> File
> "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/plotting/plot.py",
> line 193, in show
> self._backend.show()
> File
> "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/plotting/plot.py",
> line 946, in show
> self.process_series()
> File
> "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/plotting/plot.py",
> line 838, in process_series
> collection = LineCollection(s.get_segments())
> File
> "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/plotting/plot.py",
> line 461, in get_segments
> f_start = f(self.start)
> File
> "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sympy/plotting/experimental_lambdify.py",
> line 204, in __call__
> result = self.lambda_func(args)
> File "<string>", line 1, in <lambda>
> TypeError: no ordering relation is defined for complex numbers
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/QHyOEPCLCt4J.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to
> sympy+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.

Andre Holzner

unread,
Jan 12, 2013, 4:28:25 PM1/12/13
to sy...@googlegroups.com
Hi,

thanks for the prompt reply and the workaround !


On Saturday, 12 January 2013 20:45:40 UTC+1, Aaron Meurer wrote:
First off, why do you use Lambda. Just use Max(x, 5).

This is definitely a bug.  

Should I open a ticket ?
 
You can work around it by wrapping x in
re(), like plot(Max(re(x), 5)).  

in fact, doing

plot(Max(re(x),5), (x,0,10))

I get the same exception (originating at the same place)

while

plot(re(Max(x,5)), (x,0,10))

works.

thanks,

Andre


 

Aaron Meurer

unread,
Jan 12, 2013, 4:29:41 PM1/12/13
to sy...@googlegroups.com
On Jan 12, 2013, at 2:28 PM, Andre Holzner <andre....@gmail.com> wrote:

Hi,

thanks for the prompt reply and the workaround !

On Saturday, 12 January 2013 20:45:40 UTC+1, Aaron Meurer wrote:
First off, why do you use Lambda. Just use Max(x, 5).

This is definitely a bug.  

Should I open a ticket ?

Yes, please. 

 
You can work around it by wrapping x in
re(), like plot(Max(re(x), 5)).  

in fact, doing

plot(Max(re(x),5), (x,0,10))

Hmm. This worked for me. 

Aaron Meurer

To view this discussion on the web visit https://groups.google.com/d/msg/sympy/-/WBupi5qgfr8J.

Andre Holzner

unread,
Jan 12, 2013, 4:46:30 PM1/12/13
to sy...@googlegroups.com
Hello,


On Saturday, 12 January 2013 22:29:41 UTC+1, Aaron Meurer wrote:
On Jan 12, 2013, at 2:28 PM, Andre Holzner <andre....@gmail.com> wrote:

Hi,

thanks for the prompt reply and the workaround !

On Saturday, 12 January 2013 20:45:40 UTC+1, Aaron Meurer wrote:
First off, why do you use Lambda. Just use Max(x, 5).

This is definitely a bug.  

Should I open a ticket ?

Yes, please. 

ok, done (Issue 3591).

best regards & thanks,

Andre


Reply all
Reply to author
Forward
0 new messages