Question: what's wrong with this code?

hi, I have tried to run this program unfortunately the program give some errors.

 

 

anneal < -function(fun, N, rho, t, theta)

{y=NULL  

theta.old=theta repea {  

s=0  for k from 1 to N  

{

f.old=fun(theta.old)

 theta.new=runif(1,-1,1)+theta.old

 f.new=fun(theta.new)  

if(f.new<f.old){

 theta.star=theta.new  

s=s+1

}

 else  

{

u=runif(1)

 b=(u<=exp(-(f.new-f.old)/(t)))

 theta.star=theta.new*b+theta.old*(1-b)

 s=s+b  

}  

theta.old=theta.star

 y=c(y,theta.star)  

}  

write(y,file="anneal.result",ncol=1,append=T)

y=NULL

 if(s==0)break

 t=rho*t  

if(t<0.1)break  }

 return(y)  

}

cauchy.1=function(alpha){x=c(-4.20,-2.85,-2.30,-1.02,0.70,0.98,2.72,3.50)  return(sum(log(0.01+(x-alpha)^(2))))}

x=seq(-6,6,,300)

y=sapply(as.list(x),cauchy.1)

plot(x, y, type = "1", ylab = "cauchy.1(beta=.1,alpha)", xlab = "alpha")

anneal.result=anneal(cauchy.1,300,.95,10,4)

plot(x, y, type = "1", ylab = "cauchy.1(beta=.1,alpha)", xlab = "alpha")

anneal.result=anneal(cauchy.1,300,.95,10,4)

x = scan("anneal.result")

plot(1:length(x),x,type="1"

 

can anyone help me on this? can i do something about it

Many thanks.

Please Wait...