Oliver Block wrote:
> On Mon, Feb 23, 2009 at 05:40:39AM -0600, Jason Grout wrote:
> [...]
>> Yes, that is correct. When someone calls plot(h(f), 0, 20), then h is
>> evaluated at f first, so if f was 10, then plot(h(f), 0, 20) is exactly
>> the same as plot(0, 0, 20). In order to call h with the numeric values
>> between 0 and 20, you need to pass the *function* h, not the output of
>> evaluating the function at f.
>>
>> Things would work differently if h was a symbolic expression, rather
>> than a python function. For example:
>>
>> h(x) = sin(x)
>>
>> plot(h(x), (x, 0, 20))
>>
>> or
>>
>> plot(h, 0, 20)
>>
>> would both give the expected plot, because h(x) is sin(x) (i.e., a
>> function, not a number), and h is the function x |--> sin(x).
> And why does
>
> plot(h(x), (x, 0, 20))
>
> with h defined as in Stephanies example, not work?
>
> I thought, sage would evaluate h(x) for x values between 0 and 20 and
> then plot this. Why does this work for h(x) = sin(x) but not for h as
> defined in Stephanies example?
There is some magic that Sage is doing behind the scenes.
h(x) = sin(x) is really:
sage: preparse('h(x)=sin(x)')
'_=var("x");h=symbolic_expression(sin(x)).function(x)'
So, you see, h is a special Sage object.
When you do h(x), you get back an object:
sage: type(h(x))
<class 'sage.calculus.calculus.SymbolicComposition'>
This SymbolicComposition object knows how to evaluate numbers. So, for
example:
sage: (h(x))(1.0)
0.841470984807897
Therefore, plot can call whatever h(x) returns (this SymbolicComposition
object) and get back y-values.
In Steffi's example, h was a normal python function, so h(x) returned
just a number, say 34. The plot command then calls this return value
(i.e., the integer 34), but that doesn't make sense. In essence, the
plot function tries to do:
sage: (34)(1.0)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/grout/.sage/temp/good/24102/_home_grout__sage_init_sage_0.py in
<module>()
TypeError: 'sage.rings.integer.Integer' object is not callable
Does that make more sense?
Jason
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---