Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Ok, this should work.

sage: f = lambda k: Piecewise([[(-2,1),k],[(1,4),x]])
sage: P = plot(f(5))
sage: show(P)
KeyboardInterrupt
sage: A = animate([plot(f(k)) for k in [0..10]]) 
sage: show(A)

Hopefully something similar would work in an interact...

If you've never seen them, then lambda functions are mysterious, but it turns out useful for exactly this kind of thing.

I think this is probably the only reasonable way to do it, since piecewise functions automatically treat any variable in them as the function inside.

sage: var('y,z')
(y, z)
sage: g = Piecewise([[(-2,1),y^2],[(1,4),-z^2]])
sage: plot(g)