[R] Using functions that contain sums

Patrick M. Joyce patrick.joyce at huskymail.uconn.edu
Fri Sep 26 18:49:39 CEST 2008


Hello,

I'm trying to perform an integration on a function that contains a sum. 
Similarly I'm hoping whatever acts as a fix will be good enough to aid in
a 2nd case as well but I've already put in a work-around for that
situation.

My code example is here:

watermelon=c(0,1,2,3)

w<-function(x){
sum(sin(x-watermelon))}

integrate(function(x){w(x)},0,2)

integrate(function(x){sin(x)+sin(x-1)+sin(x-2)+sin(x-3)},0,2)

the first integral gives an error... the 2nd is what I should get for an
answer for the first.  Is there a way to get this to work the way that I
desire?

Any help is appreciated.

Sincerely,
Patrick Joyce



More information about the R-help mailing list