# linear regression of a reponse matrix data<-read.table("ex03.dat") names(data)<-c("x1","x2","y") x<-seq(-2,10,0.1) y<-seq(-6,10,0.1) Xcon <- data.frame(rep(x,length(y)), rep(y, each=length(x))) names(Xcon) <- c("x1","x2") g <- lm( y ~ x1 + x2 + I(x1*x1) + I(x2*x2), data = data) g.pr <- predict(g, Xcon) text.x1=paste("x1=", format(g$coefficients["x1"], digits=3)) text.x2=paste("x2=", format(g$coefficients["x2"], digits=3)) text.x12=paste("x1^2=", format(g$coefficients["I(x1 * x1)"], digits=3)) text.x22=paste("x2^2=", format(g$coefficients["I(x2 * x2)"], digits=3)) text.i=paste("Int=", format(g$coefficients["(Intercept)"], digits=3)) plot(data$x1,data$x2, xlim=c(-2,10), ylim=c(-6,10), type="n") points(data$x1,data$x2,col=(data$y+1)) contour(x,y,matrix(g.pr,length(x),length(y)), levels=0.5, labex = 0, add=T) title("Regression of Response Matrix") mtext(paste(text.i,text.x1,text.x2,text.x12,text.x22))