library("TDA") # create data set containing 100 randomly choosen # points from a circle of radius r = 1 circle1 = circleUnif(100, r = 1) # create 2x2 matrix A <- matrix(c(1, 2, 2, 0), nrow=2, ncol=2) C <- t(circle1) # take the transpose of A M <- A %*% C # multiply A and C E <- eigen(A) # calculate eigenvalues and eigenvectors of A E # display E (note its data structure) ?E plot(t(M), asp=1) # note M is the image of circle C under map A # Add an eigenvector to this plot (red asterisk) #points(c(0,E\$values[1]*E\$vectors[1,1]),c(0,E\$values[1]*E\$vectors[2,1])) arrows(0,0,E\$values[1]*E\$vectors[1,1],E\$values[1]*E\$vectors[2,1], col="red", lwd = 3) #points(c(0,E\$values[2]*E\$vectors[1,2]),c(0,E\$values[2]*E\$vectors[2,2])) arrows(0,0,E\$values[2]*E\$vectors[1,2],E\$values[2]*E\$vectors[2,2], col="blue", lwd = 3) plot(t(M), asp=1) # note M is the image of circle C under map A # Add an eigenvector to this plot (red asterisk) points(t(E\$values[1]*E\$vectors[,1]), pch=8, cex = 2, col=rgb(1, 0, 0)) # Add another eigenvector to this plot (blue asterisk) points(t(E\$values[2]*E\$vectors[,2]), pch=8, cex = 2, col=rgb(0, 0, 1)) # Add origin (0, 0) to plot (green +). points(t(c(0, 0)), pch=3, cex = 2, col=rgb(0, 1, 0)) E\$vectors[,1] A %*% E\$vectors[,1] E\$values[1] * E\$vectors[,1] - A %*% E\$vectors[,1] E\$values[1] abline(a=0, b=1) sphere <- sphereUnif(100, 2, r = 1) disk1 <- subset(sphere, select = -c(3) ) disk2 <- cbind(disk1[,1] + 4, disk1[,2]) disk3 <- cbind(disk1[,1], disk1[,2] + 4) disk4 <- disk1 + 4 noise1 <- cbind(runif(100, -1,5), runif(100, -1,5)) noisy_disk <- rbind(disk1, disk2, disk3, disk4, noise1) plot(noisy_disk, asp = 1) line <- cbind(runif(40, -.1,.1), runif(40, 1,3)) new <- rbind(noisy_disk, line) plot(new, asp = 1)