Re: [R] lower and upper limits in integrate as vectors

2008-09-20 Thread baptiste auguie

Hi,

I think you want to Vectorize integrate(), not integrand(). Here's a  
way using mapply,



integrand - function(z)
{
return(z * z)
}

vec1-1:3
vec2-2:4

mapply(integrate, lower=vec1, upper=vec2, MoreArgs=list(f=integrand) )


baptiste

On 20 Sep 2008, at 13:08, Andreas Wittmann wrote:


Dear R useRs,

i try to integrate the following function for many values

integrand - function(z)
{
return(z * z)
}

i do this with a for-loop

for(i in 2:4)
{
z - integrate(integrand, i-1, i)$value
cat(z, z, \n)
}

to speed up the computation for many values i tried vectors
in integrate to do this.

vec1-1:3
vec2-2:4

integrate(Vectorize(integrand), vec1, vec2)$value

but here it seems the integration works only for the first values of  
vec1 and vec2.


If you have any advice how i can to this computations with vectors  
or something like that, i would be very thankful,


best regards

Andreas

__
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.


_

Baptiste AuguiƩ

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
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.


Re: [R] lower and upper limits in integrate as vectors

2008-09-20 Thread Andreas Wittmann

dear baptiste,

thank you very much, that was excatly what i was looking for:-)

best regards

Andreas




baptiste auguie wrote:

Hi,

I think you want to Vectorize integrate(), not integrand(). Here's a 
way using mapply,



integrand - function(z)
{
return(z * z)
}

vec1-1:3
vec2-2:4

mapply(integrate, lower=vec1, upper=vec2, MoreArgs=list(f=integrand) )


baptiste

On 20 Sep 2008, at 13:08, Andreas Wittmann wrote:


Dear R useRs,

i try to integrate the following function for many values

integrand - function(z)
{
return(z * z)
}

i do this with a for-loop

for(i in 2:4)
{
z - integrate(integrand, i-1, i)$value
cat(z, z, \n)
}

to speed up the computation for many values i tried vectors
in integrate to do this.

vec1-1:3
vec2-2:4

integrate(Vectorize(integrand), vec1, vec2)$value

but here it seems the integration works only for the first values of 
vec1 and vec2.


If you have any advice how i can to this computations with vectors or 
something like that, i would be very thankful,


best regards

Andreas

__
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.


_

Baptiste AuguiƩ

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag
__



__
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.