Hello,

On Wed, Oct 28, 2009 at 9:55 PM, Erik <[email protected]> wrote:
>
> I would like to iterate a function:
>
> def f(x):
>    return( (1/5)*(x**3+x**2-3) )
> f(0)
>
> Running evaluate on the above yields the quantity -3/5. Rather than
> evaluating f(-3/5), is there a way to reference the previous output
> from evaluate, i.e. to evaluate f(previous) or some similar syntax?

On the Sage command line, the previous result is stored in _.  So, you
can do f(_).

> Similarly, is there a way to use the syntax "for i in range()" to
> define the next i as f(i)? I know that "for i in range(-2,2,i=f(i))"

I'm not exactly sure what you want, but here's my best guess.  You
could use a while loop.

i = -2
while i < 2:
    do_something()
    i = f(i)

--Mike

--~--~---------~--~----~------------~-------~--~----~
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
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to