APLICANDO LOS CONOCIMIENTOS DE RSTUDIO
En este documento se presentan 7 ejercicios de aprendizaje simple y básico sobre matrices.
AUTORES
COLABORACIÓN
- EJERCICIO 1
\[ A= \begin{pmatrix} 1&2&3\\ 2&4&6\\ 3&6&9\\ 4&8&12\\ \end{pmatrix} \]
A <- matrix(c(1,2,3,2,4,6,3,6,9,4,8,12),ncol = 3, byrow = T)
A
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 2 4 6
## [3,] 3 6 9
## [4,] 4 8 12
- EJERCICIO 2
\[ I= \begin{pmatrix} 1&0&0&0\\ 0&1&0&0\\ 0&0&1&0\\ 0&0&0&1\\ \end{pmatrix} \]
I<-diag(c(1,1,1,1))
I
## [,1] [,2] [,3] [,4]
## [1,] 1 0 0 0
## [2,] 0 1 0 0
## [3,] 0 0 1 0
## [4,] 0 0 0 1
- EJERCICIO 3
\[ L= \begin{pmatrix} 1&2&-4\\ -1&-1&5\\ 2&7&-3\\ \end{pmatrix} \]
L <- matrix(c(1,2,-4,-1,-1,5,2,7,-3), ncol=3, byrow = T)
L
## [,1] [,2] [,3]
## [1,] 1 2 -4
## [2,] -1 -1 5
## [3,] 2 7 -3
# Instalación del paquete "matlib"
# install.packages("matlib")
library(matlib)
## Warning: package 'matlib' was built under R version 4.1.3
# Matriz inversa de L
L2<-Inverse(L)
L2
## [,1] [,2] [,3]
## [1,] -16.0 -11.0 3.0
## [2,] 3.5 2.5 -0.5
## [3,] -2.5 -1.5 0.5
- EJERCICIO 4
\[ P= \begin{pmatrix} 1&2&3&0&2\\ 2&4&6&0&3\\ 3&6&9&0&5\\ 4&8&12&0&7\\ 5&10&15&5&11\\ 6&12&18&5&13\\ 7&14&21&5&17\\ 8&16&24&5&19\\ 9&18&27&5&23\\ \end{pmatrix} \]
# Búsqueda de la dirección del archivo excel en su PC, se detalla un ejemplo de como se debe tomar la dirección del archivo.
# file.choose()
# Ingreso del archivo excel como csv
ruta_excel <- ("\\Users\\gaby_\\OneDrive\\Documentos\\Silabos de la U\\Tercer Semestre UCE\\PROGRAMACION\\TALLER 6\\Matriz de R.csv")
P <- read.csv(ruta_excel,sep = ",")
P
## X1 X2 X3 X4 X5
## 1 1 2 3 0 2
## 2 2 4 6 0 3
## 3 3 6 9 0 5
## 4 4 8 12 0 7
## 5 5 10 15 5 11
## 6 6 12 18 5 13
## 7 7 14 21 5 17
## 8 8 16 24 5 19
## 9 9 18 27 5 23
# Renombramiento de filas y columnas
colnames(P) = c("[,1]","[,2]","[,3]","[,4]","[,5]")
rownames(P) = c("[1,]","[2,]","[3,]","[4,]","[5,]","[6,]","[7,]","[8,]","[9,]")
P
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 2 3 0 2
## [2,] 2 4 6 0 3
## [3,] 3 6 9 0 5
## [4,] 4 8 12 0 7
## [5,] 5 10 15 5 11
## [6,] 6 12 18 5 13
## [7,] 7 14 21 5 17
## [8,] 8 16 24 5 19
## [9,] 9 18 27 5 23
- EJERCICIO 5
\[ \left\{ \begin{array}{ll} x +5y =7\\ -2x-7y=-5 \end{array} \right. \]
a <- rbind(c(1, 5),c(-2, -7))
a
## [,1] [,2]
## [1,] 1 5
## [2,] -2 -7
b <- c(7, -5)
b
## [1] 7 -5
solve(a, b)
## [1] -8 3
- EJERCICIO 6
\[ A= \begin{pmatrix} 1&4&9\\ 7&2&5\\ 6&8&3\\ \end{pmatrix} \] \[ \begin{array}{ll} |A| = (1*2*3)\\ \ \ \ \ \ +(4*5*6)\\ \ \ \ \ \ +(7*8*9)\\ \ \ \ \ \ -(9*2*6)\\ \ \ \ \ \ -(4*7*3)\\ \ \ \ \ \ -(5*8*1)\\ \ \ \ \ \ =6+120+504-108-84-40\\ \ \ \ \ \ =398 \end{array} \]
c <- matrix(c(1,4,9,7,2,5,6,8,3), nrow = 3, byrow = T)
c
## [,1] [,2] [,3]
## [1,] 1 4 9
## [2,] 7 2 5
## [3,] 6 8 3
det(c)
## [1] 398
- EJERCICIO 7
\[ A= \begin{pmatrix} [1]&2&3\\ [4]&5&6\\ [7]&8&9\\ \end{pmatrix} \] \[ A^T= \begin{pmatrix} [1]&[4]&[7]\\ 2&5&8\\ 3&6&9\\ \end{pmatrix} \]
B <- matrix(1:9, nrow = 3, byrow = T)
B
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 4 5 6
## [3,] 7 8 9
t(B)
## [,1] [,2] [,3]
## [1,] 1 4 7
## [2,] 2 5 8
## [3,] 3 6 9