Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to take a free-form input Function to create a list using NestList.

  Manipulate[list2 = NestList[f, .8, 10], {f, (1/3) x^3, InputField[_, String]}, 
     ControlType -> InputField]

Which generates this output:

{0.8, ((x^3)/3)[0.8], ((x^3)/3)[((x^3)/3)[0.8]], ((x^3)/ 3)[((x^3)/3)[((x^3)/3)[0.8]]], ((x^3)/ 3)[((x^3)/3)[((x^3)/3)[((x^3)/3)[0.8]]]], ((x^3)/ 3)[((x^3)/3)[((x^3)/3)[((x^3)/3)[((x^3)/3)[0.8]]]]], ((x^3)/ 3)[((x^3)/3)[((x^3)/3)[((x^3)/3)[((x^3)/3)[((x^3)/3)[0.8]]]]]], (( x^3)/3)[((x^3)/ 3)[((x^3)/3)[((x^3)/3)[((x^3)/3)[((x^3)/3)[((x^3)/3)[0.8]]]]]]], (( x^3)/3)[((x^3)/ 3)[((x^3)/ 3)[((x^3)/ 3)[((x^3)/3)[((x^3)/3)[((x^3)/3)[((x^3)/3)[0.8]]]]]]]], ((x^3)/ 3)[((x^3)/ 3)[((x^3)/ 3)[((x^3)/ 3)[((x^3)/ 3)[((x^3)/3)[((x^3)/3)[((x^3)/3)[((x^3)/3)[0.8]]]]]]]]], ((x^3)/ 3)[((x^3)/ 3)[((x^3)/ 3)[((x^3)/ 3)[((x^3)/ 3)[((x^3)/ 3)[((x^3)/3)[((x^3)/3)[((x^3)/3)[((x^3)/3)[0.8]]]]]]]]]]}

I would like to have a numeric output.

share|improve this question
The problem is in function definition, x does not mean anything in this form. Try (1/3) #^3 & – Kuba Jun 13 '13 at 19:15
up vote 3 down vote accepted

As I have mentioned in comment the problem is that (1/3)x^3 is not a proper function definition. Applying this to Your starting value will give You, as one can expect:

(* => (1/3)x^3 [.8]*)

Natural way is to use pure function form for it: (1/3)#^3&.

 list2 = NestList[f, .8, 10], 
 {f, (1/3) #^3 &, InputField[_]}, ControlType -> InputField]

enter image description here

But it does not look good in InputField, it is also not convenient to type. The following solution will fix that:

 list2 = NestList[f /. x -> # &, .8, 10],
 {f, (1/3) x^3, InputField[_]}, ControlType -> InputField]

enter image description here

share|improve this answer
Thank-you Kuba! Nice solution. – twhoward99 Jun 13 '13 at 19:47
What happens if the user enters 42 + u^3? :P – m_goldberg Apr 18 '14 at 22:57
@m_goldberg well, nothing special, I;m not sure what do you mean :P – Kuba Apr 19 '14 at 6:45

Your Answer


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.