MathGroup Archive 2006

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

Search the Archive

Re: NestWhile iterator.


I too remember seeing the post you're talking about but don't remember
its subject, so here's a routine that counts the Newton iterations for
a square root.

In[1]:= mysqrt[a_] := NestWhile[{#[[1]]+1, .5(#[[2]]+a/#[[2]])}&,
                                {0, Max[1.,N@a]}, #[[2]]^2 > a&]
In[2]:= mysqrt[2]
Out[2]= {5, 1.41421}


  • Prev by Date: Re: Extract any diagonal from a square matrix...
  • Next by Date: Re: what is K$
  • Previous by thread: NestWhile iterator.
  • Next by thread: Re: NestWhile iterator.