[Rcpp-devel] uniroot problem

Shaami nzshaam at gmail.com
Tue Dec 24 01:45:50 CET 2019


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/20191224/8e8caa8e/attachment.html>


More information about the Rcpp-devel mailing list