Hello ,I am trying to write a loop for sum of integrals . the integral is:integrand4<-function(x,a=1.5,n=3,k=0){(((a+1)*x)^k)*((2-x)^n)*(exp(-a*x-2))/(factorial(k)*factorial(n))}
integrate(integrand4,0,2). I need a loop to give me the sum of integrals over k = 0,.....n , for every positive integer input (n).can anybody check my program and tell me about it's problem?I am looking forward to your suggestions. B<-function(n){Sum<-1for (k in 0:n){BB<-function(k){integrand2<-function(x,a=1.5){(((a+1)*x)^k)*((2-x)^(n))*(exp(-a*x-2))/(factorial(k)*factorial(n))} integrate(integrand2,0,2)}r<-print(BB(k))sum<-sum+r}print(sum-1)} Best Regards,Diba [[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.