title: ““Práctica de matrices en R y Publicación en Rpubs”” author: “carlos, GH20033” date: “2023-03-26” output: html_document —
##creacion de matrices. matriz y
##generacion de la matriz y
matriz_Y= matrix(data = c(20,30,36,42,40),nrow = 5,ncol = 1,
byrow = TRUE,)
colnames(matriz_Y)=c("tabla")
print(matriz_Y)
## tabla
## [1,] 20
## [2,] 30
## [3,] 36
## [4,] 42
## [5,] 40
matriz x
matriz_x <- cbind(rep(1,5),matrix(data = c(4,10,3,8,6,11,4,9,8,12),nrow = 5,ncol = 2,byrow = TRUE))
colnames(matriz_x)<- c("Cte","x1","x2")
print(matriz_x)
## Cte x1 x2
## [1,] 1 4 10
## [2,] 1 3 8
## [3,] 1 6 11
## [4,] 1 4 9
## [5,] 1 8 12
producto de matrices. calculo de x’x(sigma matriz)
matrix_XX<- t(matriz_x)%*%matriz_x
print(matrix_XX)
## Cte x1 x2
## Cte 5 25 50
## x1 25 141 262
## x2 50 262 510
sigma_matriz<- function(matriz){t(matriz)%*%matriz}
matriz_xx2=sigma_matriz(matriz_x)
print(matriz_xx2)
## Cte x1 x2
## Cte 5 25 50
## x1 25 141 262
## x2 50 262 510