Solución Ejercicio 1

mi_matriz<-matrix(data= c(1,2,3,4,
                           5,6,7,8,
                           9,10,11,12),nrow = 3, byrow = TRUE)
print(mi_matriz)
##      [,1] [,2] [,3] [,4]
## [1,]    1    2    3    4
## [2,]    5    6    7    8
## [3,]    9   10   11   12
mi_matriz2<-matrix(data= c(1,2,3,4,
                           5,6,7,8,
                           9,10,11,12),nrow = 3, byrow = FALSE) |> 
  print()
##      [,1] [,2] [,3] [,4]
## [1,]    1    4    7   10
## [2,]    2    5    8   11
## [3,]    3    6    9   12

Solución Ejercicio 2

ana <- c(10, 20, 30)
beto <- c(15, 25, 35)
unir_filas<-rbind(ana,beto)|> print()
##      [,1] [,2] [,3]
## ana    10   20   30
## beto   15   25   35
unir_columnas<-cbind(ana,beto)|> print()
##      ana beto
## [1,]  10   15
## [2,]  20   25
## [3,]  30   35
row.names(unir_filas)<-c("maria","jose")
colnames(unir_filas)<-c("examen1", "examen2","examen3")
unir_filas
##       examen1 examen2 examen3
## maria      10      20      30
## jose       15      25      35

Solución Ejercicio 3

#creación de la matriz
set.seed(50)
(mi_matriz_aleatoria<-matrix(data = sample(x = 1:100,size = 9),
                             nrow = 3,byrow = TRUE)) |> print()
##      [,1] [,2] [,3]
## [1,]   11   52   95
## [2,]   98   46   67
## [3,]    8   16   18
#calculando la transpuesta
#sin guardar:
mi_matriz_aleatoria |> t() #no se crea un objeto
##      [,1] [,2] [,3]
## [1,]   11   98    8
## [2,]   52   46   16
## [3,]   95   67   18
#con guardado:
transpuesta_mi_matriz_aleatoria<-t(mi_matriz_aleatoria) #se crea y muestra el objeto

#extrayendo elemento de la fila 2 y columna 3
transpuesta_mi_matriz_aleatoria[2,3] |> print()
## [1] 16
#multiplicando la matriz por un escalar 10
10*transpuesta_mi_matriz_aleatoria |> print()
##      [,1] [,2] [,3]
## [1,]   11   98    8
## [2,]   52   46   16
## [3,]   95   67   18
##      [,1] [,2] [,3]
## [1,]  110  980   80
## [2,]  520  460  160
## [3,]  950  670  180

Solución Ejercicio 4

#creando una matriz identidad
matriz_identidad<-diag(x=1,nrow = 3) |> print()
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    0    1
#creando la matriz diagonal con los elementos c(5,10,15) en diag principal
matriz_identidad<-diag(x=c(5,10,15),nrow = 3) |> print()
##      [,1] [,2] [,3]
## [1,]    5    0    0
## [2,]    0   10    0
## [3,]    0    0   15

Solución Ejercicio 5

#ingreso de la matriz
M<-matrix(data = c(1,2,
                   3,4),nrow=2,byrow=TRUE) |> print()
##      [,1] [,2]
## [1,]    1    2
## [2,]    3    4
#1calculo de la inversa de la matriz M
M_inversa<-solve(M) |> print()
##      [,1] [,2]
## [1,] -2.0  1.0
## [2,]  1.5 -0.5
#2verificación
M %*% M_inversa |> round(digits = 0) |> print()
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1
M_inversa %*% M |> round(digits = 0) |> print()
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1
#3
matriz_no_invertible<-matrix(data = c(2,4,
                                       0,0),nrow= 2, byrow = TRUE) |> print()
##      [,1] [,2]
## [1,]    2    4
## [2,]    0    0
ifelse(det(matriz_no_invertible!=0),
       solve(matriz_no_invertible), "Matriz Singular")
## [1] "Matriz Singular"

Solución Ejercicio 6

library(matlib)
fila1<-c(2,3,5,6) 
fila2<-c(0,8,1,-7) 
fila3<-fila1+fila2 
(matriz_para_rango<-matrix(data=c(fila1,
                                 fila2,
                                 fila3), nrow=3, byrow= TRUE)) |> print()
##      [,1] [,2] [,3] [,4]
## [1,]    2    3    5    6
## [2,]    0    8    1   -7
## [3,]    2   11    6   -1
#Calculo del rango de la matriz
rango<-matlib::R(X = matriz_para_rango) |> print()
## [1] 2

Solución Ejercicio 7

#creando la matriz simetrica
S<-matrix(data = c(2,1,
                   1,2), nrow=2, byrow = TRUE) |> print()
##      [,1] [,2]
## [1,]    2    1
## [2,]    1    2
#creando los autovalores (y tmb los autovectores)
resultado<-eigen(S)
#autovalores
resultado$values
## [1] 3 1
#verificar los autovalores
det(S-resultado$values[1]*diag(x=1,2))
## [1] 0
det(S-resultado$values[2]*diag(x=1,2))
## [1] 0

Solución Ejercicio 8

A<-matrix(data = c(2,3,1,
                  1,-2,4,
                  3,1,-1), nrow=3, byrow=TRUE) |> print()
##      [,1] [,2] [,3]
## [1,]    2    3    1
## [2,]    1   -2    4
## [3,]    3    1   -1
B<-matrix(data= c(1,-3,4), ncol=1, byrow= TRUE) |> print()
##      [,1]
## [1,]    1
## [2,]   -3
## [3,]    4
#matriz aumentada S
S<-cbind(A,B) |> print()
##      [,1] [,2] [,3] [,4]
## [1,]    2    3    1    1
## [2,]    1   -2    4   -3
## [3,]    3    1   -1    4
#teorema de Rouche Frobenius
matlib::R(S)==matlib::R(A)
## [1] TRUE
#resolver el sistema de ecuaciones
solucion<-solve(A,B) |> print()
##      [,1]
## [1,]    1
## [2,]    0
## [3,]   -1
#VERIFICACION
A%*%solucion-B
##      [,1]
## [1,]    0
## [2,]    0
## [3,]    0

Solucion Ejercicio 9

library(matlib)
matlib::gaussianElimination(A,B, verbose = TRUE, fractions = TRUE)
## 
## Initial matrix:
##      [,1] [,2] [,3] [,4]
## [1,]  2    3    1    1  
## [2,]  1   -2    4   -3  
## [3,]  3    1   -1    4  
## 
## row: 1 
## 
##  exchange rows 1 and 3
##      [,1] [,2] [,3] [,4]
## [1,]  3    1   -1    4  
## [2,]  1   -2    4   -3  
## [3,]  2    3    1    1  
## 
##  multiply row 1 by 1/3
##      [,1] [,2] [,3] [,4]
## [1,]    1  1/3 -1/3  4/3
## [2,]    1   -2    4   -3
## [3,]    2    3    1    1
## 
##  subtract row 1 from row 2
##      [,1]  [,2]  [,3]  [,4] 
## [1,]     1   1/3  -1/3   4/3
## [2,]     0  -7/3  13/3 -13/3
## [3,]     2     3     1     1
## 
##  multiply row 1 by 2 and subtract from row 3
##      [,1]  [,2]  [,3]  [,4] 
## [1,]     1   1/3  -1/3   4/3
## [2,]     0  -7/3  13/3 -13/3
## [3,]     0   7/3   5/3  -5/3
## 
## row: 2 
## 
##  multiply row 2 by -3/7
##      [,1]  [,2]  [,3]  [,4] 
## [1,]     1   1/3  -1/3   4/3
## [2,]     0     1 -13/7  13/7
## [3,]     0   7/3   5/3  -5/3
## 
##  multiply row 2 by 1/3 and subtract from row 1
##      [,1]  [,2]  [,3]  [,4] 
## [1,]     1     0   2/7   5/7
## [2,]     0     1 -13/7  13/7
## [3,]     0   7/3   5/3  -5/3
## 
##  multiply row 2 by 7/3 and subtract from row 3
##      [,1]  [,2]  [,3]  [,4] 
## [1,]     1     0   2/7   5/7
## [2,]     0     1 -13/7  13/7
## [3,]     0     0     6    -6
## 
## row: 3 
## 
##  multiply row 3 by 1/6
##      [,1]  [,2]  [,3]  [,4] 
## [1,]     1     0   2/7   5/7
## [2,]     0     1 -13/7  13/7
## [3,]     0     0     1    -1
## 
##  multiply row 3 by 2/7 and subtract from row 1
##      [,1]  [,2]  [,3]  [,4] 
## [1,]     1     0     0     1
## [2,]     0     1 -13/7  13/7
## [3,]     0     0     1    -1
## 
##  multiply row 3 by 13/7 and add to row 2
##      [,1] [,2] [,3] [,4]
## [1,]  1    0    0    1  
## [2,]  0    1    0    0  
## [3,]  0    0    1   -1