# Revision history [back]

Another option is to use the (not very powerful) Piecewise class. You could at least do some basic calculus with it as well, then. However, you'd have to define endpoints.

sage: g = Piecewise([[(-10,1),x], [(1,10),x^2]], x)
sage: derivative(g)
Piecewise defined function with 2 parts, [[(-10, 1), x |--> 1], [(1, 10), x |--> 2*x]]
sage: integrate(g)
Piecewise defined function with 2 parts, [[(-10, 1), x |--> 1/2*x^2 - 50], [(1, 10), x |--> 1/3*x^3 - 299/6]]
sage: plot(g)


So it works. But see ticket 11225 for a nice list of ways in which piecewise plotting could be improved. For instance, with infinite endpoints, although it does math, it won't plot. Perhaps that makes sense, since we wouldn't see infinity anyway...

sage: f = Piecewise([[(-oo,1),x], [(1,oo),x^2]], x)
sage: f(-10^6)
-1000000
sage: plot(f)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
ValueError: cannot convert float NaN to integer