Hello,

The following code of mine is giving the error:

Error in integrate(fx[[2]], 0.056, 1) :
  maximum number of subdivisions reached

Can anyone help?

Thanks and Regards.

Swagato

--------------------------

fv<-vector("list")
fx<-vector("list")

v<-0
c<-0
n<-0
NOV<-0
i<-0

while(n<200){
fv[[1]]<-function(x)1 #prior function

fx[[1]]<-function(x){
  rho<-(0.2+6*x)/(.3+4*x)
  i<-0
  N<-0
  for(i in 1:length(x)){

kopt<-function(K){(x[i]-0.05*(K-((1-rho[i]^K)/(1-rho[i])+(K*rho[i]^(K+1)-1))/(1-rho[i]^(K+1)))/(0.1+5*x[i]))^2}

  L<-optim(c(0),kopt,method="BFGS")
  N[i]<-round(L$par+1)}
  return(N)
} # Calculate Kv+1

fx[[2]]<-function(x)((0.2+6*x)/(.3+4*x))^n*(1-(0.2+6*x)/(.3+4*x))/(1-(0.2+6*x)/(.3+4*x))^fx[[1]](x)*fv[[1]](x)

# numerator of f'
gx<-integrate(fx[[2]],0,0.045) #denomenator of f'
hx<-integrate(fx[[2]],0.056,1)
fv[[2]]<-function(x)x*fx[[2]](x)/(gx$value+hx$value) #v.f'

fx[[3]]<-function(x){
  NV<-0;n0<-0;
  rho<-(0.2+6*x)/(.3+4*x)
  i<-0
  N<-0
  for(i in 1:length(x)){

kopt<-function(K){(x[i]-0.05*(K-((1-rho[i]^K)/(1-rho[i])+(K*rho[i]^(K+1)-1))/(1-rho[i]^(K+1)))/(0.1+5*x[i]))^2}

  L<-optim(c(0),kopt,method="BFGS")
  N[i]<-L$par+1
  j<-0
  for(j in 0:N[i]) NV[i]<- NV[i] +
j*(rho[i])^j*(1-rho[i])/(1-rho[i]^(N[i]+1))
  n0[i]<-n}

  return(0.05*(n0-NV)/(0.1+5*x))
         }#cost function
fv[[3]]<-function(x)fx[[3]](x)*fx[[2]](x)/(gx$value+hx$value)
fv[[4]]<-function(x)(n-fx[[3]](x)*(0.1+5*x)/0.05)*fx[[2]](x)/(gx$value+hx$value)



a1<-integrate(fv[[2]],0,0.045)
a2<-integrate(fv[[2]],0.056,1)
v[n]<-a1$value+a2$value #expected value

b1<-integrate(fv[[3]],0,0.045)
b2<-integrate(fv[[3]],0.056,1)
c[n]<-b1$value+b2$value #expected cost

d1<-integrate(fv[[4]],0,0.045)
d2<-integrate(fv[[4]],0.056,1)
NOV[n]<-d1$value+d2$value #expected length
n<-n+1
}
plot(v)
plot(c)
plot(NOV)
l<-1/(1+exp(v-c))
plot(l)

        [[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.

Reply via email to