x <- c(1,2,4,6); y <- 1/x
xP <- setupInterp(x,y,TRUE)
xT <- setupInterp(x,y,FALSE)
x0 <- seq(0,7,0.1); yP <- evalInterp(x0,xP)
yT <- evalInterp(x0,xT)
plot(x,y,xlim=c(-0.5,7.5),ylim=c(min(y)-2,max(y)+2),cex=2)
lines(x0,yP,col=2,cex=0.5)
lines(x0,yT,col=4,cex=0.5,pch="+")
legend(x="bottom",c("polynomial", "rational"), col = c(2,4),
text.col= "black", lty = 1, merge = TRUE, bg='white')
minInterp(x,(x-3)^2,add=FALSE,doPoly=TRUE) # 3
minInterp(x,(x+1.0/x),add=FALSE,doPoly=FALSE) # 1 -1
minInterp(x,(x+1.0/x),add=TRUE,doPoly=TRUE) # 8.3471982 0.3194685
Run the code above in your browser using DataLab