0

I am attempting to make a small interactive plot that displays the plot of Cos iterated its times. Whenever I try to evaluate my cell, however, I get a Nest:intnm error, something like:

Nest::intnm: Non-negative machine-sized integer expected at position 3 in Nest[Cos,0.000128356,100].

As you can see, the 3rd argument for Nest is an integer, but Mathematica is not happy with it. Here is my code:

DynamicModule[{its=100},Column[{Plot[Nest[Cos,x,Dynamic[its]],{x,0,2\[Pi]}],Slider[Dynamic[its],{1,500,1}]}]]

I've tried changing Nest[Cos,x,Dynamic[its]] to Nest[Cos,x,IntegerPart[Dynamic[its]]] (so as to catch any sort of glitch where 100 was not seen as an integer) with no avail. This is my first time dealing with anything dynamic, or even sliders, so any help is appreciated.

diracdeltafunk
  • 215
  • 1
  • 2
  • 7
  • 1
    Dynamic[its] is not an integer. How about Manipulate[ Plot[Nest[Cos, x, its], {x, 0, 2 \[Pi]}], {{its, 1, "its"}, Range[1, 500], ControlType -> Slider}] ? – b.gates.you.know.what Jun 26 '13 at 07:38
  • 2
    perhaps you want Dynamic[Plot[... rather than Plot[..Dynamic[its]]? – cormullion Jun 26 '13 at 07:40
  • @b.gatessucks I tried to account for that possibility by passing it through IntegerPart (discussed in my question), but that did not help. How can I fix this issue? – diracdeltafunk Jun 26 '13 at 07:40
  • @b.gatessucks oh sorry, didn't see that last bit. I'll try that. – diracdeltafunk Jun 26 '13 at 07:40
  • @cormullion what is the difference? sorry, I am new at this. – diracdeltafunk Jun 26 '13 at 07:41
  • Ben, I've marked this question as a duplicate as the issue is the same in both cases. The simplest thing is to move the Dynamic outside of Plot, but you need to understand what is going on here or you're in for a lot of headache. Try this: DynamicModule[{its = 1}, Column[{Dynamic@Plot[Nest[Cos, x, its], {x, 0, 2 \[Pi]}], Slider[Dynamic[its], {1, 80, 1}]}]] – Mr.Wizard Jun 26 '13 at 07:42
  • @Mr.Wizard Thank you – diracdeltafunk Jun 26 '13 at 07:43
  • @Mr.Wizard Vitaliy Kaurov: "...generally the price of dynamic updating is change of Head." – Kuba Jun 26 '13 at 08:04
  • @Kuba I'm not sure why that commented is directed to me. Anyway, I think the issue is explained quite well by John Fultz in the post that is linked from my answer to the original question linked above. – Mr.Wizard Jun 26 '13 at 21:06

0 Answers0