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) <[EMAIL PROTECTED]>
Fax-to-email: +44 (0)870 094 0861
Date: 19-Apr-07                                       Time: 14:01:51
------------------------------ XFMail ------------------------------

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to