Re: [R] Using integrate

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Mon, 21 Jul 2008 19:43:47 -0400

On 21/07/2008 4:56 PM, Ayman Oweida wrote:
> I have a function, say:
> f<-function(x) exp(x)
>
> and I would like to obtain the integration of the function while adding a few operations within the integration (I need point-by-point integration), say:
>
> t<-seq(0,40, by=1)
> z<-array(0,length(t))
> for (i in 1:40){
> z[i] <- integrate ( f * (t [i+1] - t) , (i-1) , i )
>
> In R, I can only have the function in 'integrate'
> i.e.
> z[i] <- integrate ( f , (i-1) , i )
>
> but I want to add additional operations within the 'integrate' command, which I cannot just add to the function f.

But it is very simple to define new functions. So you could do

z[i] <- integrate( function(x) f(x) * (t [i+1] - t[i]), i-1, i )

Duncan Murdoch



R-help_at_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. Received on Mon 21 Jul 2008 - 23:47:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Jul 2008 - 01:32:13 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive