# graph of a (three) piece-wise function f(x): f(x)=x when # x is in [0,1], f(x)=x/2+0.5 when x is in [1,2], and (x^2-1)/2 # when x is in [2,3]. # You can call the file that contains these codes whatever you # want, say, example. # You then can run this program under R prompt ">" (Of course, # you have to activate R first). Then just type # source("example") after splus prompt ">". Then you will have # a ps file that contains the graph of the above function. # Note that usually we run R codes interactively, especially # for a small task. # Be aware that R is case-sensitive! # Here the sign "#" means comment postscript(file="example.ps", horizontal = F, height=6, width=8.5) # par(mfrow=c(1,2)) x <- seq(0, 1, length=50) fx <- x plot(x, fx, xlab="x", ylab="f(x)", xlim=c(0,3), ylim=c(0,4), type="l") x <- seq(1, 2, length=50) fx <- x/2 + 0.5 lines(x, fx, lty=1) x <- seq(2, 3, length=50) fx <- (x^2-1)/2 lines(x, fx, lty=1) title("A three piece-wise function", cex=0.9) # you can "cex=" to control the size of the title dev.off()