#EIGENVECTORS AND EIGENVALUES: #MAKING MATRIX M: M=matrix(c(5,-2,-3,2),nrow=2,ncol=2,byrow=T) M #COMPUTING EIGENVALUES AND EIGENVECTORS OF MATRIX M: E=eigen(M) E #SHOWING EIGENVECTORS: #FUNCTION make.grid() FINDS POINTS ON A GRID: make.grid <- function(Xsize,Ysize){ ii=0 jj=0 X=numeric(0) Y=numeric(0) for(i in 1:Xsize) { for(j in 1:Ysize) { ii=ii+1 X[ii]=i if(j==Ysize) j=0 jj=jj+1 Y[jj] = j } } X Y M=cbind(X-mean(X),Y-mean(Y)) return(M) } 1 X=make.grid(10,10) M=matrix(c(1.0,0.3,0.3,1),nrow=2,ncol=2,byrow=T)1 E=eigen(M) #LINEAR TRANSFORMATION: Z=M%*%t(X) Z=t(Z) #PLOT TRANSFORMATION VECTORS: plot(Z,type='n',xlab='X',ylab='Y') arrows(X[,1],X[,2],Z[,1],Z[,2],col='purple',lwd=1,code=2,length=0.05) arrows(0,0,8*E$vectors[,1],8*E$vectors[,2],col='red',code=2,length=0.05)