Re: FixedPoint vs. FixedPointList
- To: mathgroup at smc.vnet.net
- Subject: [mg24488] Re: [mg24384] FixedPoint vs. FixedPointList
- From: "John D. Hendrickson" <jdh at hend.net>
- Date: Wed, 19 Jul 2000 01:22:00 -0400 (EDT)
- Organization: home
- References: <8l0qd5$dvj@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
(Mathematica book page 243)
FixedPoint simply calls your function unil the result no longer changes.
You can easily write a function which does the same. The difference being,
your function would keep track of the iterations.
In[467]:=
myFixedPoint[f_, x_] :=
Module[{n = 0, y = x + 1, y1 = x},
While[y != y1,
y = y1;
++n;
y1 = f[y]];
{y1, n}
]
(* test - same as one in Mathematica Book *)
In[472]:=
myFixedPoint[Log, 1. + \[ImaginaryI]]
Out[472]=
{0.318132\[InvisibleSpace] + 1.33724 \[ImaginaryI], 101}
In[473]:=
Log[%[[1]]]
Out[473]=
0.318132\[InvisibleSpace] + 1.33724 \[ImaginaryI]
so we have { solution, iterations } as the output
BobHanlon at aol.com wrote in message <8l0qd5$dvj at smc.vnet.net>...
>
>In a message dated 7/12/2000 11:43:32 PM, linsuain+ at andrew.cmu.edu writes:
>
>>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?
>>
>
>poly[x_] := x^5 - x^4 + 2 x^3 - x^2 + 3;
>
>n = 1;
>
>FixedPoint[(n++; # - poly[#]/poly'[#]) &, 2.]
>
>-0.8574417862415682
>
>n
>
>23
>
>Length[FixedPointList[(n++; # - poly[#]/poly'[#]) &, 2.]]
>
>23
>
>
>Bob Hanlon
>