# example from the correlation matrix # Jun tavg stations USW00014771 USW00094728 # correlation matrix rm(list=ls()) source("scripts/myfunctions.R") # covariance matrix between USW00014771 and USW00094728 # tavg June monthly mean anomalies C<-matrix(c(1.4732,0.7530,0.7530,1.1516),2,2) # eigenvectors # e1=c(1.502,-0.8683) # e2=c(-0.8683,1.5019) # find the direction where input (black) # and output vector (red) have same direction #plot_vector(x) # as a test criterion I us the scaling factors # if the x component of the new vector # and the y component are stretched/squeezed by the same factor # the ratio l1/l2 will be 1.0 print(" input angle, vector x-coordinate, y-coordinate, scaling ratio") for (i in seq(0,360,10)) { phi<-i/180.0*pi print(paste("test vector in direction of phi= ",round(phi/pi*180.,2))) x<-c(cos(phi),sin(phi)) y<-C%*%x # when l1<-y[1]/x[1] l2<-y[2]/x[2] print(paste(i,x[1],x[2],l1/l2)) plot(c(-3,3),c(-3,3),typ='n',xlab='x1',ylab='x2') plot_vector(x,col=1) plot_vector(y,col=2) res<-readline("enter for next testing the next direction ('q' for exit)") if (res=='q') {break} }