[R] help me to debug this part of code?
jinjin
hj_suzhou at hotmail.com
Fri Apr 18 17:05:07 CEST 2008
I am trying to solve the integration equation, for different values of K from
4 to 25, the integration is with respect to u,
Here is the equation: gamma(k/2) / ( sqrt(k-1)*gamma((k-1)/2) ) *
integrate(f= (1+u^2/k-1)^(-k/2), lower=0, upper= sqrt(a^2*k/(k+1-a^2)) ) =
the similar expression as te left hand except k becomes k+1
my code is below, I don't know why R keep telling me the syntax wrong but I
am not clear, thanks.
f<-function(u,k){(1+u^2/(k-1))^(-k/2)}
g<-function(u,k){(1+u^2/k)^(-(k+1)/2)}
for(k in 4:25){
out<-uniroot(function(a){
m<-exp(lgamma(k/2)-lgamma((k-1)/2))*1/sqrt(k-1)
n<-exp(lgamma((k+1)/2)-lgamma(k/2)*1/sqrt(k)
m*integrate(f,lower=0,upper=sqrt(a^2*(k-1)/(k-a^2)),rel.tol=.Machine$double.eps^0.25)
-n*integrate(g,lower=0,upper=sqrt(a^2*k/(k+1-a^2)),rel.tol=.Machine$double.eps^0.25)
}
lower=1.4, upper=2)
print(unlist(out))}
--
View this message in context: http://www.nabble.com/help-me-to-debug-this-part-of-code--tp16763482p16763482.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list