Dear R experts, I am trying to find all the solutions of an equation. Here is an example:
integrand1<- function(x){1/x*dnorm(x)} integrand2<- function(x){1/(2*x-50)*dnorm(x)} integrand3<- function(x,C){ cd<- 1/(x+C) return(cd) } res<- function(C){ ce<-integrate(integrand1, lower=1, upper=50)$value+ integrate(integrand2, lower=50, upper=100)$value-integrate(integrand3, C=C,lower=1, upper=100)$value return(ce) } I want to find all the roots of res. First, I used uniroot to ensure that a solution existed, and it works. uniroot(res, c(1,1000)) But, there might be other roots, and I wanted to use the function uniroot. library(rootSolve) uniroot.all(res, c(1,1000)) I obtain an error message: "Error in integrate(integrand3, C = C, lower = 1, upper = 100) : evaluation of function gave a result of wrong length In addition: Warning message: In x + C : longer object length is not a multiple of shorter object length" I don't understand what is wrong? Thank you very much for any suggestion! Aurelien [[alternative HTML version deleted]] ______________________________________________ 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.