Thank you Peter. That is very much helpful. If you don't mind, I continued running the code to attempt to get my answer and I continue to get inf inf inf....... (printed around 100 times). Any assistance with this issue. Here is my code (including your corrections):
myquadrature<-function(f,a,b){ npts=length(f) nint=npts-1 if(npts<=1) error('need at least two points to integrate') end; if(b<=a) error('something wrong with the interval, b should be greater than a') else dx=b/real(nint) end; npts=length(f) int=0 int <- sum(f[-npts]+f[-1])/2*dx } #Call my quadrature x=seq(0,2000,10) h = 10.*(cos(((2*pi)/2000)*(x-mean(x)))+1) u = 1.*(cos(((2*pi)/2000)*(x-mean(x)))+1) a = x[1] b = x[length(x)] plot(x,-h) a = x[1]; b = x[length(x)]; #call your quadrature function. Hint, the answer should be 30000. f=u*h; val = myquadrature(f,a,b); ? ___________This is where issue arises. result=myquadrature(val,0,2000) ? print(result) ? Thanks again, Phil [[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.