Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6153

Re: iteration question

From Szabolcs Horvát <szhorvat@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: iteration question
Date 2011-11-03 08:57 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j8tl13$f34$1@smc.vnet.net> (permalink)
References <j8r9b8$3ie$1@smc.vnet.net>

Show all headers | View raw


On 2011.11.02. 12:25, Francisco Gutierrez wrote:
> Dear Group:
>
> I have a function, and I iterate it using fixedpoint. Something of this sort:
>
> FixedPointList[
>   function[arg1,arg2,arg3, #]&, arg4,
>   SameTest ->  (Max[Abs[Flatten[#1] - Flatten[#2]]]<  0.01&)]
>
>
> I would like to know how many steps it takes this function to converge. I have tried with EvaluationMonitor to no avail:
>
> Block[{veamos, c = 0},
>    veamos = FixedPoint[
>      function[arg1,arg2,arg3, #]&, arg4,
>      SameTest ->  (Max[Abs[Flatten[#1] - Flatten[#2]]]<  0.01&)];
>    EvaluationMonitor :>  c++; {veamos, c}]
>
>
> The iterator c simply does not move, and the previous function works ok but returns the value of c as 0.
>
> I tried if this was true with Length[FixedPointList[...]] and the answer was 20 (which should be the value of c in the immediately previous function). In principle, this would solve my problem, but it seems
> rather inefficient, especially when the convergence criterion is severe (not 0.01, but say 10^-4).
>
> Is there an efficient and nice way to solve this?
>

Neither FixedPoint, not Block take the option EvaluationMonitor.  Also, 
the option was included incorrectly in Block.  Options must be separated 
by a colon, not semicolon.

I seriously doubt that FixedPointList would be measurably slower than 
FixedPoint (have you measured it?), but if you really want to avoid 
FixedPointList, you can use

Module[{result, c = 0},
   result = FixedPoint[(c++; f[#])&, value];
   {result, c}
]

I'd recommend {Last[#], Length[#]}& @ FixedPointList[ ... ] though.

I hope this helps.

References:

http://reference.wolfram.com/mathematica/ref/CompoundExpression.html
http://reference.wolfram.com/mathematica/ref/Block.html

--
Szabolcs Horvát
Mathematica on SO: http://stackoverflow.com/questions/tagged/mathematica

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

iteration question Francisco Gutierrez <fgutiers2002@yahoo.com> - 2011-11-02 11:25 +0000
  Re: iteration question "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-11-03 08:46 +0000
  Re: iteration question "Dr. Wolfgang Hintze" <weh@snafu.de> - 2011-11-03 08:47 +0000
  Re: iteration question Szabolcs Horvát <szhorvat@gmail.com> - 2011-11-03 08:57 +0000
  Re: iteration question Francisco Gutierrez <fgutiers2002@yahoo.com> - 2011-11-05 09:47 +0000

csiph-web