Re: FixedPoint vs. FixedPointList
- To: mathgroup at smc.vnet.net
- Subject: [mg24431] Re: [mg24384] FixedPoint vs. FixedPointList
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Tue, 18 Jul 2000 00:58:29 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Here is one (very standard) way illustrated with the well known example of the function whose FixedPoint gives an approximate value of Sqrt[2]: In[1]:= sq[x_] := (x + 2/x)/2 In[2]:= index = 0 In[3]:= FixedPoint[(index++; sq[#]) &, 1.] Out[3]= 1.41421 In[4]:= index Out[4]= 6 Andrzej -- Andrzej Kozlowski Toyama International University, JAPAN For Mathematica related links and resources try: <http://www.sstreams.com/Mathematica/> on 7/13/00 12:13 PM, Otto Linsuain at linsuain+ at andrew.cmu.edu wrote: > > Hi all. I need to know the fixed point of a function (to a certain > accuracy) starting from a certain value of the arguement, say: > > x = FixedPoint[ f, x, SameTest -> ( #2-#1 < somesmallnumber &) ] > > I do not care about the intermediate results, but I would like to know > how many iterations it takes for the process to converge. FixedPointList > will do, for example: > > {n,x}={Length[#],Last[#]}& @ FixedPointList[....] > > However I believe this would cause problems. The reason is that x is > really a very long list (FixedPoint works for lists too), and it could > take many iterations for this to settle. Mathematica, I believe, stores > only a maximum of two values at any given moment when executing > FixedPoint, but it stores all intermediate values for FixedPointList, > and most certainly would run out of memory. > > Could any think of how to trick Mathematica to count the iteration > without trying to store all the results? > > Any suggestions would be greatly appreciated. Otto Linsuain. >