Look at your first function: Grx<-function(x,r) { G0=Grx(x,0) G0=1; fu1<-function(t){exp(-t^2/(2*r*(r+1)))*Grx(x,r-1)} return(integrate(fu1,0,x)$value) }
It immediately calls itself for infinite recursion. How did you expect to stop it? I would have expected some type of test before the call. I put a counter in and it was 1661 levels down in the call at the error. On Fri, Aug 20, 2010 at 9:33 AM, Shant Ch <sha1...@yahoo.com> wrote: > Hi, > > I wanted to compute the value of the function ifn at certain values of n. But > I > am receiving the following error when I was using the following code(given at > the end). > > Error: evaluation nested too deeply: infinite recursion / > options(expressions=)? > > I feel that since the function Grx is recursively related, perhaps making the > code too complicated too handle. Can anyone let me know if there is any other > way to handle this problem? > > > d1=10.5 > Grx<-function(x,r) > { > G0=Grx(x,0) > G0=1; > fu1<-function(t){exp(-t^2/(2*r*(r+1)))*Grx(x,r-1)} > return(integrate(fu1,0,x)$value) > } > > grx<-function(x,r) > { > Grx(x)*exp(-x^2/(2*(r+1))) > } > > ifn<-function(n) > { > w=n*d1/2;S1=0; > for(k in 1:(n-1)) > { > S1=S1+choose(n,k)*grx(w,k)*grx(w,n-k-1) > } > return(S1); > } > > ifn(5) > > Thanks in advance. > > Shant > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org 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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? ______________________________________________ R-help@r-project.org 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.