MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: NestWhile iterator.


Hey, that's an elegant solution. Since calculating the square root
above is very ... definite, I remembered something "off-topic" and
wanted to try out: how would one compare the last two result of
NestWhile in order to stop the calculation? With supplying the fourth
argument to the function.
With counting the iterations, let's solve for the intersection of y =
cos(x) and y = x with an error tolerance of 0.001:

In[13]:=
NestWhile[{#[[1]]+1,Cos[#[[2]]]}&,
  {0,.5},
  Abs[#1[[2]]-#2[[2]]]>.001&,
  2]

Out[13]=
{16, 0.738705}


Bye,
Borut Levart
Slovenia


  • Prev by Date: Re: want real solutions instead of complex ones
  • Next by Date: Mathlink and Intel C++ compiler
  • Previous by thread: Re: NestWhile iterator.
  • Next by thread: Lists and rules