#278 Plot in R
png(file="D:/projects/wordpress/ex278/ex278a.png",width=600, height=600) f.piecewise=function(x){ifelse(x<2,sin(x),x^2)} curve(f.piecewise,-3,3,type="p",ylab="A Piecewise Function") grid(NULL,NULL,col="black") dev.off() png(file="D:/projects/wordpress/ex278/ex278b.png",width=600, height=600) curve(f.piecewise,-3,3,type="n",ylab="A Piecewise Function") grid(NULL,NULL,col="black") curve(f.piecewise,-3,1.95,add=TRUE,lwd=2) curve(f.piecewise,2,3,add=TRUE,lwd=2) points(2,sin(2),pch=1,cex=1.5,lwd=2) points(2,f.piecewise(2),pch=16,cex=1.5) dev.off()
Recent Comments