On Sep 13, 2:35 am, Jason Merrill <[EMAIL PROTECTED]> wrote:
> On Sep 12, 4:48 pm, Sand Wraith <[EMAIL PROTECTED]> wrote:
>
> > Hi all! Help please again :-)
>
> > here is worksheet describes my problem:
>
> >http://75.75.6.176/home/pub/8/
>
> > so, at the last stem i have wrong result: 0 instead of 2/3.
>
> > what i am doing wrong?
>
> It looks like there are a few problems here, but the main thing is
> that when you call myrect(x), it just returns 0.
>
> def rect(tau=0,t=0):
>    if (t==tau) or (t==-tau):
>        return 0.5
>    elif (t>-tau) and (t<tau):
>        return 1
>    else:
>        return 0;
>
> def myrect(x):
>    return rect(1,x);
>
> sage: myrect(x)
> 0
>
> The reason is that when you compare a symbolic variable, x, to a
> number, 1, and force sage to come up with a True or False answer, as
> if and elif do, the answer is basically always False.
>
> sage: bool(x == 1)
> False
> sage: bool(x < 1)
> False
> sage: bool(x > 1)
> False
> sage: bool(x < -1)
> False
>
> etc.
>
> Because of this, when you call myrect(x), things fall down to the last
> branch of your definition.  When an expression appears as an argument
> to a function, it is evaluated *before* the function is called.  For
> instance, look at
>
> sage: plot(myrect(x),(x,-3,3)) # The line segment y == 0
>
> In this case, myrect(x) evaluates to 0 *before* plot has a chance to
> pass in any values, and the same thing is happening to integral.
>
> I'd like to tell you that you can do what you want using piecewise, or
> something like that, but actually I don't see any way at all to make
> integral, which needs something that can act like a SymbolicExpression
> as its first argument, do what you want.  Maybe someone else will
> know.
>
> Regards,
>
> JM

I have redefine rect function:
rect=Piecewise([
[(-10,-1),(lambda x:0)],
[(- 1, 1),(lambda x:1)],
[( 1, 10),(lambda x:0)]
]);

and i have another two questions:

1) rect.plot() - is it the only way of plotting? i'd like to use
plot(rect,-4,4), but it leads to error:

>verbose 0 (3729: plot.py, __call__) there were 4 extra arguments
>(besides <function <lambda> at 0xa9382cc>)
>Traceback (click to the left for traceback)
>...
>UnboundLocalError: local variable 'G' referenced before assignment

2)How can i define another function like rect*f(x) ? and plot it?
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to