Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I can't figure out what I'm doing wrong here:

Table[Nest[# + 0.1 * -i *  #^2 &, 2, 1] , {i, 0, 0.5, 0.1}]
(* {2., 1.96, 1.92, 1.88, 1.84, 1.8} *)

The problem is that it keeps using 2 in the argument instead of the last result. Normally the first parameter is the starting point, when using the pure function.

The output should be something like

(* {2., 1.96, 1.883, 1.777, 1.651, 1.514} *)
share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Mathematica does do the right thing. For your purpose, Fold or FoldList should be used.

FoldList[#1 + 0.1*-#2*#1^2 &, 2.0, Range[0.1, 0.5, 0.1]]

Mathematica gives

{2.,1.96,1.88317,1.77678,1.6505,1.51429}

Exactly what you want.

share|improve this answer
    
Okay thanks. I thought i was possible to use Nest(List) here, because if you nest 3 or 4 times fx you use the last result each time. But im still a rookie it appears :) –  Punchline Dec 17 '13 at 9:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.