[R] loop
pari hesabi
statistics84 at hotmail.com
Mon Oct 6 00:01:57 CEST 2014
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]]
More information about the R-help
mailing list