El comando que permite introducir matrices en RStudio es matrix().
Para construir una matriz B escribimos: B <−matrix(c(); ncol =; nrow =)
Donde 𝑐() corresponde al vector de las entradas de la matriz A separadas por comas y siguiendo el orden de las columnas, además 𝑛𝑐𝑜𝑙 corresponde al número de columnas y 𝑛𝑟𝑜𝑤 el número de filas.
\[\begin{equation} \begin{pmatrix} 1 & 2 & 3\\ 2 & 4 & 6\\ 3 & 6 & 9\\ 4 & 8 & 12 \end{pmatrix} \end{equation}\]
La digitación de las entradas de la matriz en RStudio es:
A <- matrix(c(1,2,3,2,4,6,3,6,9,4,8,12),nrow = 4, byrow = T)
A
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 2 4 6
## [3,] 3 6 9
## [4,] 4 8 12
\[\begin{equation} \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1 \end{pmatrix} \end{equation}\]
I <- matrix(c(1,0,0,0),nrow = 4,byrow = T)
I
## [,1]
## [1,] 1
## [2,] 0
## [3,] 0
## [4,] 0
I <- cbind(I,c(0,1,0,0))
I <- cbind(I,c(0,0,1,0))
I <- cbind(I,c(0,0,0,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
\[\begin{equation} \begin{pmatrix} 1 & 2 & -4\\ -1 & -1 & 5\\ 2 & 7 & -3 \end{pmatrix} \end{equation}\]
install.packages("matlib")
matriz <- matrix(c(1,2,-4,-1,-1,5,2,7,-3),nrow = 3,ncol = 3,byrow = TRUE)
matriz
## [,1] [,2] [,3]
## [1,] 1 2 -4
## [2,] -1 -1 5
## [3,] 2 7 -3
inversa <- (solve(matriz))
inversa
## [,1] [,2] [,3]
## [1,] -16.0 -11.0 3.0
## [2,] 3.5 2.5 -0.5
## [3,] -2.5 -1.5 0.5
\[\begin{equation} \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} \end{equation}\]
hacerlo pero desde un archivo en excel (investigar como hacerlo)
library(readxl)
file.choose("C:/Users/salom/AppData/Local/R/win-library/4.2")
ruta_excel <- "C:\\Users\\salom\\OneDrive\\Lenguaje De Programación\\Matriz P.xlsx"
matrizp <- read_excel(ruta_excel,sheet = "Hoja1",range = "C2:G11")
matrizp
\[\begin{equation} \left\{ \begin{array}{rl} x + 5y = 7 \\ -2x -7y = -5 \end{array} \right. \end{equation}\]
Puede usar el comando solve (investigue como hacerlo)
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
\[\begin{equation} \begin{pmatrix} 1 & 4 & 9\\ 7 & 2 & 5\\ 6 & 8 & 3 \end{pmatrix} \end{equation}\]
m1<-matrix(c(1,4,9,7,2,5,6,8,3),nrow=3,byrow = T)
m1
## [,1] [,2] [,3]
## [1,] 1 4 9
## [2,] 7 2 5
## [3,] 6 8 3
det(m1)
## [1] 398
\[\begin{equation} \begin{pmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{pmatrix} \end{equation}\]
A1 <- c(1,4,7)
A2 <- c(2,5,8)
A3 <- c(3,6,9)
MatrizA <- cbind(A1,A2,A3)
MatrizA
## A1 A2 A3
## [1,] 1 2 3
## [2,] 4 5 6
## [3,] 7 8 9
ATranspuesta=cbind(A1,A2,A3)
t(ATranspuesta)
## [,1] [,2] [,3]
## A1 1 4 7
## A2 2 5 8
## A3 3 6 9