############################################### #Modified From the uniroot help file of S-Plus ############################################## #####First, create a general cubic whose root will be known (since we supply them!) cubic <- function(x, c2, c1, c0) {(x - c2) * (x - c1) * (x - c0)} #####Now test uniroot one out example with specific values of the roots: uniroot(cubic, c(1,3), keep.xy=T, c2=-2, c1=0, c0=2) #####Now a more elaborate (incrutable?) version of cubic: cubic <- function(x, c2, c1, c0, nf=0, all=list(x=NULL, y=NULL)) { value <- (x - c0) * (x - c1) * (x - c2) attributes(value) <- list(nf=nf + length(x), all=list(x=c(all$x, x), y=c(all$y, value))) value } ######And a test of the solver uniroot(cubic, lower=1, upper=3, c2=-2, c1=0, c0=2) ######################################### #Related Functions: ########################################## nlregb , optimize , polyroot, nlmin.