First time here? Check out the FAQ!

Ask Your Question
1

Plot picewise function + infinity, error message

asked 13 years ago

sagefan gravatar image

updated 2 years ago

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]])
plot(f)
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/decorators.py", 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/decorators.py", 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/plot.py", 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/piecewise.py", 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/decorators.py", 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/decorators.py", 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/plot.py", 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/plot.py", 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/plot.py", 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/misc.py", 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/misc.py", line 1242, in xsrange
    icount = int(math.ceil(float(count) - endpoint_tolerance))
ValueError: cannot convert float NaN to integer
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 13 years ago

kcrisman gravatar image

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

Basically,

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

works.

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

Preview: (hide)
link

Comments

1

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

sagefan gravatar imagesagefan ( 13 years ago )

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 ( 13 years ago )

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 13 years ago

Seen: 1,033 times

Last updated: Nov 03 '11