Slightly different solution to generate and store the values:

def f(x):
    return (1/5)*(x**3+x**2-3)
answers = [f(0)]
for i in range(5):
    answers.append(f(answers[-1]))

..and then answers will be a list of the first 6 iterated values.

-Marshall Hampton

On Oct 28, 8:55 am, 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?
> 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))"
> does not work. I've briefly searched the tutorial, this Google group,
> and Google generally without finding solutions. However, today is my
> first day using Sage.
>
> I'm running  Sage 4.1.2 pre-compiled 32 bit binary for Debian Lenny.
>
> Thanks.
--~--~---------~--~----~------------~-------~--~----~
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