MathGroup Archive 2006

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

Search the Archive

Re: NestWhile iterator.

  • To: mathgroup at
  • Subject: [mg66534] Re: NestWhile iterator.
  • From: "Ray Koopman" <koopman at>
  • Date: Fri, 19 May 2006 03:39:37 -0400 (EDT)
  • References: <e4bivp$1ap$>
  • Sender: owner-wri-mathgroup at

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.