1 | initial version |
You can get the documentation about piecewise functions by typing Piecewise?
In your particular case, you can do:
sage: f1(x) = 0
sage: f2(x) = exp(-x^2/(1-x^2))
sage: f = Piecewise([[(-2,-1),f1],[(-1,1),f2],[(1,2),f1]])
sage: f.plot()
2 | No.2 Revision |
You can get the documentation about piecewise functions by typing Piecewise?
In your particular case, you can do:
sage: f1(x) = 0
sage: f2(x) = exp(-x^2/(1-x^2))
sage: f = Piecewise([[(-2,-1),f1],[(-1,1),f2],[(1,2),f1]])
sage: f.plot()
EDIT : i did not answer the second part of your question. Indeed, if you do:
sage: g(x) = x
sage: h(x) = x^2
sage: parametric_plot3d([f, g, h], (x, -2, 2))
Then you get the following error:
AttributeError: PiecewisePolynomial instance has no attribute '__float__'
This is because parametric_plot3d
needs to evaluate the function f
with the __float__
method that does not exists for piecewise functions. However, piecewise finctions are able to evaluate on floating points (with the __call__
method):
sage: f(0.1)
0.989949833766045
So, a possible wotrkaround is to redirect the __float__
method for piecewise functions to the __call__
method that currently works:
sage: f.__float__ = f.__call__
Now, the following works:
sage: parametric_plot3d([f, g, h], (x, -2, 2))