pikkus=156 names(pikkus)=c("Juku") 1:9 c(1, 2, 3, 4, 5, 6, 7, 8, 9) tabel=matrix(1:9, nrow=3) tabel[2, 2] tabel[, c(1, 3)] tabel[c(1, 3), ] tabel[c(1, 3), c(1, 2)] tabel2=tabel tabel2[1, 1]=25 tabel2[tabel2 %% 2 == 0] <- -1 tabel2[abs(tabel2) < 2 ] <- 0 t(tabel) > as.vector(tabel) [1] 1 2 3 4 5 6 7 8 9 > as.vector(t(tabel)) [1] 1 4 7 2 5 8 3 6 9 cbind(tabel, c(10, 11, 12)) > tabel3=matrix(1:36, nrow=6) > tabel3 [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 7 13 19 25 31 [2,] 2 8 14 20 26 32 [3,] 3 9 15 21 27 33 [4,] 4 10 16 22 28 34 [5,] 5 11 17 23 29 35 [6,] 6 12 18 24 30 36 > dim(tabel3)=c(4, 9) > tabel3 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,] 1 5 9 13 17 21 25 29 33 [2,] 2 6 10 14 18 22 26 30 34 [3,] 3 7 11 15 19 23 27 31 35 [4,] 4 8 12 16 20 24 28 32 36 tabel+1 tabel+matrix(1:9, nrow=3) > tabel3 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,] 1 5 9 13 17 21 25 29 33 [2,] 2 6 10 14 18 22 26 30 34 [3,] 3 7 11 15 19 23 27 31 35 [4,] 4 8 12 16 20 24 28 32 36 > tabel3[, 1] [1] 1 2 3 4 > tabel3[, 1]+7 [1] 8 9 10 11 > tabel3[, 1] <- tabel3[,1]+7 > tabel3 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,] 8 5 9 13 17 21 25 29 33 [2,] 9 6 10 14 18 22 26 30 34 [3,] 10 7 11 15 19 23 27 31 35 [4,] 11 8 12 16 20 24 28 32 36 tabel2=matrix(1:9, nrow=3) https://e-koolikott.ee/et/oppematerjal/15512-Lineaarvorrandisusteemide-lahendamine-determinantide-abil-7 > vs=matrix(c(3, -5, 6, 10, -9, 3, 2, 0, 2, -1, -4, -8) ,nrow=3, byrow = TRUE) > vs [,1] [,2] [,3] [,4] [1,] 3 -5 6 10 [2,] -9 3 2 0 [3,] 2 -1 -4 -8 D=det(vs[, 1:3]) Dx=det(vs[, c(4, 2, 3)]) Dy=det(vs[, c(1, 4, 3)]) Dz=det(vs[, c(1, 2, 4)]) x=Dx/D y=Dy/D z=Dz/D > vs[, 1]*x [1] 2.513514 -7.540541 1.675676 > vs[, 1] [1] 3 -9 2 > vs[, 1]*x+vs[, 2]*y+vs[, 3]*z-vs[, 4] [1] 3.552714e-15 -8.881784e-16 -3.552714e-15 ~peaaegu null #_________________ library(tidyverse) kujund=matrix(c(0, 0, 0, 2, -2, 2, 1, 2), nrow=4, byrow=TRUE) colnames(kujund)=c("x", "y") as_tibble(kujund) # A tibble: 4 x 2 x y 1 0 0 2 0 2 3 -2 2 4 1 2 as_tibble(kujund) %>% ggplot(aes(x, y)) + geom_point() yhikmaatriks=matrix(c(1, 0, 0, 1), nrow=2) kujund %*% matrix(c(1, 0, 0, 2), nrow=2) %>% {colnames(.)=c("x", "y")} kujund %*% matrix(c(1, 0, 0, 2), nrow=2) %>% {colnames(.)=c("x", "y"); .} %>% as_tibble() %>% ggplot(aes(x, y))+geom_point() # Peegeldage kujundit x-telje suhtes kujund %*% matrix(c(1, 0, 0, -1), nrow=2) %>% {colnames(.)=c("x", "y"); .} %>% as_tibble() %>% ggplot(aes(x, y))+geom_point() nurk=pi/6 keeramismaatriks=matrix( c(cos(nurk), -sin(nurk), sin(nurk), cos(nurk)), nrow=2) kujund %*% keeramismaatriks %>% {colnames(.)=c("x", "y"); .} %>% as_tibble() %>% ggplot(aes(x, y))+geom_point() nurk=2*pi/6 keeramismaatriks=matrix( c(cos(nurk), -sin(nurk), sin(nurk), cos(nurk)), nrow=2) kujund %*% keeramismaatriks %>% {colnames(.)=c("x", "y"); .} %>% as_tibble() %>% ggplot(aes(x, y))+geom_point() + xlim(c(-5, 5)) + ylim(c(-5, 5)) install.packages("animation") library(animation) joonista1=function(nurk){ keeramismaatriks=matrix( c(cos(nurk), -sin(nurk), sin(nurk), cos(nurk)), nrow=2) kujund %*% keeramismaatriks %>% {colnames(.)=c("x", "y"); .} %>% as_tibble() %>% ggplot(aes(x, y))+geom_point() + xlim(c(-5, 5)) + ylim(c(-5, 5)) } joonista1(15*pi/180) saveGIF({ print(joonista1(0)) print(joonista1(15*pi/180)) }) seq(0, 360, 10) saveGIF({ for(nurk in seq(0, 2*pi, pi/10)){ print(joonista1(nurk)) } }) saveGIF({ for(nurk in seq(0, 2*pi, pi/100)){ print(joonista1(nurk)) } }, interval=0.1, movie.name="c:/kasutaja/jaagup/video3.gif") saveGIF({ for(nr in 1:5){ print(ggplot()+xlim(c(-5, 5)) + ylim(c(-5, 5))+ annotate("text", 0, 0, label="Kujundi pööramine", size=7)) } for(nurk in seq(0, 2*pi, pi/10)){ print(joonista1(nurk)) } }) kujund=matrix(c(0, 0, 0, 2, -2, 2, 1, 2), nrow=4, byrow=TRUE) #dim(kujund) kujund=cbind(kujund, rep(1, dim(kujund)[1])) colnames(kujund)=c("x", "y", "z") kujund nihex=1 nihey=2 nihkemaatriks=matrix(c(1, 0, nihex, 0, 1, nihey, 0, 0, 1), nrow=3) kujund %*% nihkemaatriks %>% {colnames(.)=c("x", "y", "z"); .} %>% as_tibble() %>% ggplot(aes(x, y))+geom_point() + xlim(c(-5, 5)) + ylim(c(-5, 5))