[sage-support] plotting box function

2011-02-04 Thread Renato Budinich
hello, why is the below code plotting a flat function rather than a box one? renato def box(x,c): if abs(x) c: return 1 else: return 0 var('x') plot(box(x,1),(x,-3,3)) -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this

Re: [sage-support] plotting box function

2011-02-04 Thread Mike Hansen
On Fri, Feb 4, 2011 at 11:37 AM, Renato Budinich renn...@gmail.com wrote: hello, why is the below code plotting a flat function rather than a box one? When you do, plot(box(x,1),(x,-3,3)) it evaluates box(x,1) which returns 0 because the variable x is not always less than 1. You need to

Re: [sage-support] plotting box function

2011-02-04 Thread D. S. McNeil
hello, why is the below code plotting a flat function rather than a box one? There are two things going on. First, in the line plot(box(x,1),(x,-3,3)) box(x,1) is actually being evaluated when the line is executed, and not thereafter. IOW you're computing box(x, 1), which is 0, so the above

Re: [sage-support] plotting box function

2011-02-04 Thread Renato
On Fri, 4 Feb 2011 19:40:34 +0800 D. S. McNeil dsm...@gmail.com wrote: hello, why is the below code plotting a flat function rather than a box one? There are two things going on. First, in the line plot(box(x,1),(x,-3,3)) box(x,1) is actually being evaluated when the line is

Re: [sage-support] plotting box function

2011-02-04 Thread Laurent
plot(lambda x: box(x,1), (x, -3, 3)) but why does this way the execution of the function get delayed? because lambda is a way to define a function. This works more or less like the following : def MyFunction(x) return box(x,1) plot(MyFunction,(x,-3,3)) See for example