[R] integration function
Uwe Ligges
ligges at statistik.uni-dortmund.de
Fri Feb 4 13:56:15 CET 2005
Christoph Scherber wrote:
> 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)
integrate() expects a function, you specify a vector of values ....
Uwe Liges
> print(c$integral)
> }}
>
> integral(y,-3,3,0.1)
>
> Best regards
> Christoph
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list