[Rcpp-devel] uniroot problem

Shaami nzshaam at gmail.com
Sun Dec 29 04:48:27 CET 2019


Any suggestion plz. What could be missing that I donot get function root to
be zero at some points?

On Tue, 24 Dec 2019, 1:45 PM Shaami, <nzshaam at gmail.com> wrote:

> Dear Friends
>
> Could you please help with the following example? I do not get function
> value at zero using uniroot() in R. Could you suggest something? I want
> function value zero at any point like 2.4, 2.5, 2.6, 4.5, 5.9 etc.
>
> Thank You
>
> x = c(-100, -20, 100, 230, 500, 920, 1000)
> a = c(1000, 12, 300, 0, 100, 300, 750)
> Fn = function(t, x, a){
>   sum = 0
>   for(i in 1:length(x)){
>     sum = sum + punif(t, min=x[i]-a[i], max=x[i]+a[i])
>   }
>   return(sum)
> }uniroot(function(t){Fn(t, x, a) - 2.4}, interval=c(min(x-a), max(x+a)))
> uniroot(function(t){Fn(t, x, a) - 2.5}, interval=c(min(x-a), max(x+a)))
> uniroot(function(t){Fn(t, x, a) - 2.8}, interval=c(min(x-a), max(x+a)))
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20191229/7e69b501/attachment.html>


More information about the Rcpp-devel mailing list