[R] Help with iteration using while loop

From: Subodh Acharya <shoebodh_at_gmail.com>
Date: Fri, 04 Jun 2010 13:30:18 -0400

Hello everyone,

I am trying to use while loop to iterate a function until convergence. But I am having problem when I try to use a fixed number of iterations. Say I want to use maximum iteration of 150. If the value don't converge within maximum iteration, show warning of no convergence.

Currently I don't have non- convergence problem so I think my code works fine. But in future I may encounter such problem that are likely to not converge easily.

Below is my function that is working when I don't provide maximum iteration.

iter<- function (Fpi, Time, tolerance){

S = 22.4
Ts = 0.499
Ti = 0.25

K = 0.044
r<- 1.5
M = Ts- Ti
Ks = 0.044
     Fpt = K*Time + M*S*log(1+ Fpi/(M*S))
       while((Fpt-Fpi) > tolerance) {
         Fpi = Fpt
             Fpt = K*Time + M*S*log(1+ Fpi/(M*S))
     Fp0 = Fpt


x<- iter(Fpi = 0.224, Time = 0.2, tolerance = 0.000001)

But I want do something like this ( conceptually) for( i in 2:itermax) {
  Fpt[i] = K*Time + M*S*log(1+ Fpi/(M*S)) if((Fpt[i]- Fpt[i-1])<= tolerance) break print(Fpt[i]

something like this.

any kind of help is highly appreciated.
thank you

Acharya, Subodh

	[[alternative HTML version deleted]]

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 04 Jun 2010 - 17:33:20 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 04 Jun 2010 - 21:10:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive