Re: [R] problem with integrate() - correction

From: Rainer M Krug <rkrug_at_sun.ac.za>
Date: Thu 22 Jun 2006 - 23:07:28 EST

Thanks a lot - the symbolic solution will work and I understand what is wrong with my function

Rainer

Frede Aakmann Tøgersen wrote:
> Well why not do it symbolically, e.g.
>
> int(a*x^b,x) = \frac{a}{b+1}x^{b+1}
>
> and integrating this again gives
>
> \frac{a}{(b+1)(b+2)}x^{b+2},
>
> of course for resonable values of a and b such that things are well defined.
>
> But if you follow the link
>
> https://stat.ethz.ch/pipermail/r-help/2005-January/064026.html
>
> you may come to this solution:
>
>
> ip <- function(x) 1240 * x^(-0.88)
>
> iip <- function(x){
> res <- rep(NA,length(x))
> for (i in seq(along=x))
> res[i] <- integrate(ip, x[i] - 0.045, x[i] + 0.045)$value
> return(res)
> }
>
> f <- integrate(iip, 10, 100)
>
> which may not be an effective way to do it.
>
>
> Med venlig hilsen
> Frede Aakmann Tøgersen
>
>
>
>

>> -----Oprindelig meddelelse-----
>> Fra: r-help-bounces@stat.math.ethz.ch 
>> [mailto:r-help-bounces@stat.math.ethz.ch] På vegne af Rainer M Krug
>> Sendt: 22. juni 2006 14:03
>> Til: rkrug@sun.ac.za
>> Cc: R help list
>> Emne: [R] problem with integrate() - correction
>>
>> Sorry
>>
>> should read:
>>
>> ip <- function(x) 1240 * x^(-0.88)
>>
>>
>> Rainer M Krug wrote:
>>> Hi
>>>
>>> System:
>>> Linux, SuSE 10
>>> R 2.3.0
>>>
>>> I try to do the following
>>>
>>>> ip <- function(x) 1240*dip(x, 0.88)
>>>> iip <- function(x) integrate(ip, x - 0.045, x + 0.045)$value f <- 
>>>> integrate(iip, 10, 100)
>>> Error in integrate(iip, 10, 100) : evaluation of function gave a 
>>> result of wrong length
>>>
>>> How can I solve this?
>>>
>>> Thanks
>>>
>>> Rainer
>>>
>>>
>>>
>>
>> --
>> Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT)
>>
>> Department of Conservation Ecology and Entomology University 
>> of Stellenbosch Matieland 7602 South Africa
>>
>> Tel:		+27 - (0)72 808 2975 (w)
>> Fax:		+27 - (0)21 808 3304
>> Cell:		+27 - (0)83 9479 042
>>
>> email:	RKrug@sun.ac.za
>>       	Rainer@krugs.de
>>
>> ______________________________________________
>> R-help@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
>>


-- 
Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation
Biology (UCT)

Department of Conservation Ecology and Entomology
University of Stellenbosch
Matieland 7602
South Africa

Tel:		+27 - (0)72 808 2975 (w)
Fax:		+27 - (0)21 808 3304
Cell:		+27 - (0)83 9479 042

email:	RKrug@sun.ac.za
      	Rainer@krugs.de

______________________________________________
R-help@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
Received on Fri Jun 23 00:21:07 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 23 Jun 2006 - 02:12:21 EST.

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