[R] integration function

Christoph Scherber Christoph.Scherber at uni-jena.de
Fri Feb 4 13:28:46 CET 2005


Dear R users,

I have tried to write a function which gives the step-wise integral for 
an exponential function (moving from -3 to 3 in steps of 0.1, where the 
output for every step shall be the integral under the curve of y against x.

However, something seems to be wrong with this function; can anyone 
please help me?

x<-seq(-3,3,0.1)
y<-exp(x)


integral<-function(z,a,b,step){
for(i in (1:((b-a)/step))){
    c<-0
    c[i]<-integrate(z,lower=a+(i-1)*step,upper=a+i*step)
    print(c$integral)
}}

integral(y,-3,3,0.1)

Best regards
Christoph




More information about the R-help mailing list