![]() | 1 | initial version |
The way you define h
makes it a Python function, so that, when you call h
at the floating-point number 4.3
, it is evalued by entering twice the while
loop and then taking the absolute value of 4.3-2-2
, that is 0.3
.
However, when you call h
at the symbolic expression x
, the while
loop is not entered since:
sage: bool(x>1)
False
hence, the abs
function is called at the symbol x
and what is returned is the abs(x)
symbolic expression, see:
sage: abs
<built-in function abs>
sage: type(abs)
<class 'builtin_function_or_method'>
sage: abs(x)
abs(x)
sage: type(abs(x))
<class 'sage.symbolic.expression.Expression'>
Hence plot(h(x),x,0,5)
is the same as plot(abs(x),x,0,5)
. The syntax plot(foo,x,0,5)
is for plotting symbolic function, which is OK since abs(x)
is a symbolic function, but it is not what you expected. If you want the plot
function to evaluate the function foo
at various floating-points between a
and b
to make the graphics, the syntax is just plot(foo,a,b)
, without mentionning any symbol.
Hence, you should simply call
sage: plot(h,0,5)