2010/3/25 Dan Drake <dr...@kaist.edu>: > Hello, > > I'm trying to use a piecewise function, and it doesn't seem to work very > well.
This is at least the 20th email I've seen over the years that starts "I'm trying to use a piecewise function, and it doesn't seem to work". Whoever rewrites Piecewise function (and abelian groups) will be a hero. -- William > If I do > > f = Piecewise([((0, 1), x), ((1, 2), 1)], x) > > and try to evaluate f(3/2), it complains that Integer objects are not > callable. The docstring for Piecewise says "if the optional var is > specified, then any symbolic expressions in the list will be converted > to symbolic functions using fcn.function(var)" -- shouldn't it also > try to convert non-symbolic expressions? I can do SR(1), but I don't > want to get into explaining to my students what that means. > > With the above definition, I also can't easily plot the function: if I > do > > plot(f, 0, 2) > > I get "ValueError: free variable: x |--> x" and if I do > > plot(f(x), x, 0, 2) > > it complains "value not defined outside of domain". The only way I could > get the function to plot is with > > plot(lambda x: f(x), 0, 2) > > which seems like an unnecessary workaround. > > If I define the function with > > f = Piecewise([((0,1), x), ((1,2), SR(1))]) > > I still have problems; when I try to evaluate f(3/2), it says "the > number of arguments must be less than or equal to 0"!? > > I also can't seem to get diff() to work with this function, even though > f.derivative() works. > > Are these known problems? Am I not using Piecewise properly? > > Dan > > -- > --- Dan Drake > ----- http://mathsci.kaist.ac.kr/~drake > ------- > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.9 (GNU/Linux) > > iEYEARECAAYFAkusJSsACgkQr4V8SljC5LrrZQCeOOAda3+8EYthVj0FVDNvyrYV > IM4AoIOPOVn/ViU/9SguNDOGwZhKVyO1 > =iu3A > -----END PGP SIGNATURE----- > > -- William Stein Associate Professor of Mathematics University of Washington http://wstein.org -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org To unsubscribe from this group, send email to sage-devel+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.