[R] convergence
(Ted Harding)
Ted.Harding at manchester.ac.uk
Thu Apr 19 15:01:56 CEST 2007
On 19-Apr-07 12:00:17, rach.s wrote:
>
> hie..
> how can i write a loop that makes algorithm keeps repeating
> until a solution is converged?do i use a for loop? i know
> that we can use for loop to ask for a number of repetitions,
> but how to use it to ask the algorithm to keep repeating
> until a solution is converged?
> Thanks
There are various ways round this, but a 'for' loop with
a fixed number of iterations is not usully one of them!
The simplest is to use while(). A possibly strategy is
Y.old <- initial.Y
while(TRUE){
Y <- compute.Y(Y.old, ...)
if(abs(Y - Y.old) < small.number) break
Y.old <- Y
}
This will loop indefinitely until the convergence criterion
abs(Y - Y.old) < small.number
is met, and then stop.
Best wishes,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 19-Apr-07 Time: 14:01:51
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list