R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

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),ncol = 3,byrow = FALSE) |> 
print()
##      [,1] [,2] [,3]
## [1,]    1    5    9
## [2,]    2    6   10
## [3,]    3    7   11
## [4,]    4    8   12

Solución Ejercicio 2

ana <- c(10, 20, 30) 
beto <- c(15, 25, 35) 
unir_filas<-rbind(ana,beto)|> print() # se crea el objeto unir_filas y se muestra
##      [,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
rownames(unir_filas) <-c("maria","jose")
colnames(unir_filas) <-c("examen 1","examen 2","examen 3")
unir_filas
##       examen 1 examen 2 examen 3
## maria       10       20       30
## jose        15       25       35

solición ejercicio 3

set.seed(50)
(mi_matrix_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 transpuesta:
# sin guardar
mi_matrix_aleatoria |> t() #no se crea un objeto
##      [,1] [,2] [,3]
## [1,]   11   98    8
## [2,]   52   46   16
## [3,]   95   67   18
#Con guadado:
transpuesta_mi_matriz_aleatoria<-t(mi_matrix_aleatoria) |>print() #se crea un objeto
##      [,1] [,2] [,3]
## [1,]   11   98    8
## [2,]   52   46   16
## [3,]   95   67   18
#Extrayendo el elemento 2,3
transpuesta_mi_matriz_aleatoria[2,3] |>print()
## [1] 16
#multipliplicando la matriz por una escalae
10*transpuesta_mi_matriz_aleatoria[2,3] |>print()
## [1] 16
## [1] 160

#Solucion ejercicio 4

#Creando una matriz identidad:
matriz_identidad<-diag(x=1,nrow=3,ncol=3) |>print()
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
## [3,]    0    0    1
#Creando una matriz diagonal con los elementos en la diagonal principal
matriz_diagona<-diag(x=c(5,10,15), nrow=3,ncol=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
#1 calculando la inversa
M_inversa<-solve(M) |>print()
##      [,1] [,2]
## [1,] -2.0  1.0
## [2,]  1.5 -0.5
#2 verificacion
M%*% M_inversa |> round(digits=0) |> print()
##      [,1] [,2]
## [1,]    1    0
## [2,]    0    1
#3 
matriz_no_invertible_1<-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_1!=0),
       solve(matriz_no_invertible_1),"matriz singular")
## [1] "matriz singular"

solución ejercicio 6

library(matlib)
fila1<-c(2,3,5,6) |> print()
## [1] 2 3 5 6
fila2<-c(0,8,1,-7)|>print()
## [1]  0  8  1 -7
(fila3<-fila1+fila2) |>print()
## [1]  2 11  6 -1
(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
rango<-matlib::R(X=matriz_para_rango) |>print()
## [1] 2

#solución ejerccicio 7

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

#Solucion de ejercicio 8

library(matlib)
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<-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
#ES DE SOLUCION UNICA

#Resolver sistema
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)
#para ver con todos los procesos 
matlib::gaussianElimination(A,B,verbose = TRUE)
## 
## Initial matrix:
## Warning in printMatrix(A): Function is deprecated. See latexMatrix() and Eqn()
## for more recent approaches
##      [,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
## Warning in printMatrix(A): Function is deprecated. See latexMatrix() and Eqn()
## for more recent approaches
##      [,1] [,2] [,3] [,4]
## [1,]    3    1   -1    4
## [2,]    1   -2    4   -3
## [3,]    2    3    1    1
## 
##  multiply row 1 by 0.3333333
## Warning in printMatrix(A): Function is deprecated. See latexMatrix() and Eqn()
## for more recent approaches
##      [,1]       [,2]       [,3]      [,4]
## [1,]    1  0.3333333 -0.3333333  1.333333
## [2,]    1 -2.0000000  4.0000000 -3.000000
## [3,]    2  3.0000000  1.0000000  1.000000
## 
##  subtract row 1 from row 2
## Warning in printMatrix(A): Function is deprecated. See latexMatrix() and Eqn()
## for more recent approaches
##      [,1]       [,2]       [,3]      [,4]
## [1,]    1  0.3333333 -0.3333333  1.333333
## [2,]    0 -2.3333333  4.3333333 -4.333333
## [3,]    2  3.0000000  1.0000000  1.000000
## 
##  multiply row 1 by 2 and subtract from row 3
## Warning in printMatrix(A): Function is deprecated. See latexMatrix() and Eqn()
## for more recent approaches
##      [,1]       [,2]       [,3]      [,4]
## [1,]    1  0.3333333 -0.3333333  1.333333
## [2,]    0 -2.3333333  4.3333333 -4.333333
## [3,]    0  2.3333333  1.6666667 -1.666667
## 
## row: 2 
## 
##  multiply row 2 by -0.4285714
## Warning in printMatrix(A): Function is deprecated. See latexMatrix() and Eqn()
## for more recent approaches
##      [,1]      [,2]       [,3]      [,4]
## [1,]    1 0.3333333 -0.3333333  1.333333
## [2,]    0 1.0000000 -1.8571429  1.857143
## [3,]    0 2.3333333  1.6666667 -1.666667
## 
##  multiply row 2 by 0.3333333 and subtract from row 1
## Warning in printMatrix(A): Function is deprecated. See latexMatrix() and Eqn()
## for more recent approaches
##      [,1]     [,2]       [,3]       [,4]
## [1,]    1 0.000000  0.2857143  0.7142857
## [2,]    0 1.000000 -1.8571429  1.8571429
## [3,]    0 2.333333  1.6666667 -1.6666667
## 
##  multiply row 2 by 2.333333 and subtract from row 3
## Warning in printMatrix(A): Function is deprecated. See latexMatrix() and Eqn()
## for more recent approaches
##      [,1] [,2]       [,3]       [,4]
## [1,]    1    0  0.2857143  0.7142857
## [2,]    0    1 -1.8571429  1.8571429
## [3,]    0    0  6.0000000 -6.0000000
## 
## row: 3 
## 
##  multiply row 3 by 0.1666667
## Warning in printMatrix(A): Function is deprecated. See latexMatrix() and Eqn()
## for more recent approaches
##      [,1] [,2]       [,3]       [,4]
## [1,]    1    0  0.2857143  0.7142857
## [2,]    0    1 -1.8571429  1.8571429
## [3,]    0    0  1.0000000 -1.0000000
## 
##  multiply row 3 by 0.2857143 and subtract from row 1
## Warning in printMatrix(A): Function is deprecated. See latexMatrix() and Eqn()
## for more recent approaches
##      [,1] [,2]      [,3]      [,4]
## [1,]    1    0  0.000000  1.000000
## [2,]    0    1 -1.857143  1.857143
## [3,]    0    0  1.000000 -1.000000
## 
##  multiply row 3 by 1.857143 and add to row 2
## Warning in printMatrix(A): Function is deprecated. See latexMatrix() and Eqn()
## for more recent approaches
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    1
## [2,]    0    1    0    0
## [3,]    0    0    1   -1
library(matlib)
#Solo resultado final 
matlib::gaussianElimination(A,B)
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    1
## [2,]    0    1    0    0
## [3,]    0    0    1   -1