Thanks to everyone for the replies here and the direct emails from Rob
McMahon and Juan Arias de Reyna. I was trying to isolate my problem and
only succeeded in introducing more confusion. My background is that I have
been using Mathematica for teaching for the past 20+ years and find it
difficult to shake of that background. The construction for creating a list
there uses a dummy variable that does not alter the correspondng global
variable, which is why creating the table of values in Sage messed things
up unexpectedly, to me. The nature of my function, where one alternative
was not real for part of the domain also caused me confusion.
I think that I now understand what my problem is, namely that a function
created using if:... else: within a def (or inside a lambda function
definition) can, it seems, only be used for returning numerical values. Any
attempt to use it symbolically just returns the else: alternative.
E.g.
def f(x):
if x<0:
return x^2
else:
return x
After that, f(-1) returns 1 alright, but f(x) returns x, rather than some
version of the function defined. That is why plot(f,(-1,1)) works fine but
plot(f(x),(x,-1,1)) draws a straight line.
The same kind of thing happens using h=lambda x: x^2 if x<0 else x
Is there somewhere in the documentation that spells out this limitation of
the various if...else constructions?
Given my background coming from years of use of Mathematica, this seems
like a major drawback of Sage.
--
--
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org