0
$\begingroup$

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} *)
$\endgroup$

1 Answer 1

3
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 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 :) $\endgroup$
    – Punchline
    Dec 17, 2013 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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