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



--~--~---------~--~----~------------~-------~--~----~
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