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


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

Re: iteration question

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!goblin3!goblin2!goblin.stu.neva.ru!feeder1.cambriumusenet.nl!feed.tweaknews.nl!94.232.116.15.MISMATCH!ramfeed-1.ams.xsnews.nl!feed.xsnews.nl!border-1.ams.xsnews.nl!newspump.sol.net!post2.nntp.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail
From Francisco Gutierrez <fgutiers2002@yahoo.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: iteration question
Date Sat, 5 Nov 2011 09:47:51 +0000 (UTC)
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Sender steve@smc.vnet.net
Approved Steven M. Christensen <steve@smc.vnet.net>, Moderator
Message-ID <j930o7$a5u$1@smc.vnet.net> (permalink)
References <j8r9b8$3ie$1@smc.vnet.net> <201111030843.DAA15129@smc.vnet.net>
Reply-To Francisco Gutierrez <fgutiers2002@yahoo.com>
Lines 67
NNTP-Posting-Date 05 Nov 2011 08:51:48 GMT
NNTP-Posting-Host 3d865800.news.twtelecom.net
X-Trace DXC=oAoMZ8NUGH8B8ck_2OIRd8C_A=>8kQj6==_1NR_H?JP=Te8cX:a0\@4EFiONJ7[Go6EN89HhAXf51
X-Complaints-To abuse@twtelecom.net
Xref x330-a1.tempe.blueboxinc.net comp.soft-sys.math.mathematica:6209

Show key headers only | View raw


Many thanks to Szabolcs, Wolfgang, and Oleksandr for their valuable answers to my query. All very clear, and worked well.
Best,
Francisco


________________________________
From: Oleksandr Rasputinov <oleksandr_rasputinov@hmamail.com>
Sent: Thursday, November 3, 2011 3:43 AM
Subject: Re: iteration question

On Wed, 02 Nov 2011 11:25:28 -0000, Francisco Gutierrez  
<fgutiers2002@yahoo.com> 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?
>
> Thanks,
>
> Francisco

FixedPoint doesn't accept the option EvaluationMonitor, so this approach 
is a dead end. You could insert your counter into the SameTest; the number 
of comparisons will be one more than the number required to achieve 
convergence. However, I don't think this is likely to gain you very much; 
Length@FixedPointList[...] will not incur a noticeable efficiency penalty 
in most cases as building up a list of values is a fairly lightweight 
operation. Another approach, of course, would be to use a While loop.

In regard to your SameTest: you may need to be careful with comparisons of 
this sort where the absolute function values are large and the tolerance 
is small since, due to the properties of floating-point numbers, the 
relative error in this case may become arbitrarily small without the 
absolute error necessarily falling below the value required for 
convergence. Assuming that you're working in machine precision, you may be 
better off using something along the lines of

SameTest -> (val = Max[Abs[Flatten[#1] - Flatten[#2]]]; val < tol + 
val*Sqrt[$MachineEpsilon] &)

where tol is your chosen tolerance.

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous 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