Ask Your Question

Plot picewise function + infinity, error message

asked 2011-11-03 11:11:43 +0100

sagefan gravatar image

updated 2023-01-09 23:59:31 +0100

tmonteil gravatar image

If I define a piecewise function from -infinity to +infininty, and I want to plot it, I get an error message like below. Any ideas how to fix this? Any workarounds?

f = Piecewise([[(-infinity,1),1],[(1,+infinity),2]])
Traceback (most recent call last):
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/misc/", line 657, in wrapper
    return func(*args, **kwds)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/misc/", line 504, in wrapper
    return func(*args, **options)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/plot/", line 3058, in plot
    G = funcs.plot(*args, **original_opts)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/functions/", line 1018, in plot
    return sum([plot(f, a, b, *args, **kwds) for (a,b),f in self.list()])
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/misc/", line 657, in wrapper
    return func(*args, **kwds)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/misc/", line 504, in wrapper
    return func(*args, **options)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/plot/", line 3077, in plot
    G = _plot(funcs, (xmin, xmax), *args, **kwds)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/plot/", line 3180, in _plot
    data = generate_plot_points(f, xrange, plot_points, adaptive_tolerance, adaptive_recursion, randomize)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/plot/", line 4180, in generate_plot_points
    data = srange(*ranges[0], include_endpoint=True)
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/misc/", line 1149, in srange
    L = list(xsrange(start,end,step,universe,check,include_endpoint,endpoint_tolerance))
  File "/opt/sage-4.7.1-linux-64bit-ubuntu_10.04.1_lts-x86_64-Linux/local/lib/python2.6/site-packages/sage/misc/", line 1242, in xsrange
    icount = int(math.ceil(float(count) - endpoint_tolerance))
ValueError: cannot convert float NaN to integer
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2011-11-03 12:02:01 +0100

kcrisman gravatar image

This is also known, and there are some workarounds at Ticket 11225.


sage: f = Piecewise([[(-1000,1),1],[(1,1000),2]])
sage: plot(f)


However, it's helpful to know that people really do want to use this code!

edit flag offensive delete link more



Thanks for the workaround. Would be great if the bug would be fixed soon.

sagefan gravatar imagesagefan ( 2011-11-04 16:42:42 +0100 )edit

Unlikely, unfortunately, as the codebase is idiosyncratic and some work with internals of some other component program of Sage would be needed to fix piecewise correctly. I don't think too many people are motivated to do it piecemeal right now.

kcrisman gravatar imagekcrisman ( 2011-11-04 22:52:02 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-11-03 11:11:43 +0100

Seen: 927 times

Last updated: Nov 03 '11