“Exercises section 3”

Exercise 3.1

Statistical programming on the R plataform

Faculty of Economics - Course: MINE_008

Author: Nicolás Romero Alfonso & Laura Molina.

Identity card: 1000573650

Copyright 2024

Email: ,

Date: 2024-06-18

Script Name: Exercise 3.1_R_Script_MINE_VIII_Nicolás-Romero_Laura-Molina

Description: Proper syntax exercises to strengthen programming skills in R

Version: 1.0

First steps

rm(list = ls())                                    
objects()
## character(0)
getwd()  
## [1] "C:/Users/nicor/OneDrive - Universidad Externado de Colombia/MINE - 008/PSIS/Scripts/prog_001"
basename(getwd())
## [1] "prog_001"
dirname(getwd())
## [1] "C:/Users/nicor/OneDrive - Universidad Externado de Colombia/MINE - 008/PSIS/Scripts"
cat("/014")     
## /014

A.

PREGUNTAR SI EL POR FILAS O POR COLUMNA.

matriz <- matrix(data = c(4.3, 3.1, 8.2, 8.2, 3.2, 0.9, 1.6, 6.5), 4, 2, byrow = T); matriz
##      [,1] [,2]
## [1,]  4.3  3.1
## [2,]  8.2  8.2
## [3,]  3.2  0.9
## [4,]  1.6  6.5

B.

matriz_2 <- matriz[-1,];matriz_2
##      [,1] [,2]
## [1,]  8.2  8.2
## [2,]  3.2  0.9
## [3,]  1.6  6.5
dim(matriz_2)
## [1] 3 2

C.

matriz[,2] <- sort(matriz[,2]); matriz
##      [,1] [,2]
## [1,]  4.3  0.9
## [2,]  8.2  3.1
## [3,]  3.2  6.5
## [4,]  1.6  8.2

D.

matriz_3 <- matriz[-4, -1]
resultado_1 <- matrix(matriz_3, ncol = 1); resultado_1
##      [,1]
## [1,]  0.9
## [2,]  3.1
## [3,]  6.5

E.

matriz_4 <- matrix(matriz[3:4,], 2); matriz_4
##      [,1] [,2]
## [1,]  3.2  6.5
## [2,]  1.6  8.2

F.

diagonal <- (-1/2) *diag(matriz_4);diagonal
## [1] -1.6 -4.1
matriz[4, 2] <- diagonal[2]
matriz[1, 2] <- diagonal[2]
matriz[4, 1] <- diagonal[1]
matriz[1, 1] <- diagonal[1]
matriz
##      [,1] [,2]
## [1,] -1.6 -4.1
## [2,]  8.2  3.1
## [3,]  3.2  6.5
## [4,] -1.6 -4.1

Exercise 3.2

Statistical programming on the R plataform

Faculty of Economics - Course: MINE_008

Author: Nicolás Romero Alfonso & Laura Molina.

Identity card: 1000573650

Copyright 2024

Email: ,

Date: 2024-06-18

Script Name: Exercise 3.2_R_Script_MINE_VIII_Nicolás-Romero_Laura-Molina

Description: Proper syntax exercises to strengthen programming skills in R

Version: 1.0

First steps

rm(list = ls())                                    
objects()
## character(0)
getwd()  
## [1] "C:/Users/nicor/OneDrive - Universidad Externado de Colombia/MINE - 008/PSIS/Scripts/prog_001"
basename(getwd())
## [1] "prog_001"
dirname(getwd())
## [1] "C:/Users/nicor/OneDrive - Universidad Externado de Colombia/MINE - 008/PSIS/Scripts"
cat("/014")     
## /014

A.

uno <- matrix(c(1,2,7,2,4,6),3)
dos <- matrix(c(10,30,50,20,40,60),3)
round((2/7)*(uno - dos),2)
##        [,1]   [,2]
## [1,]  -2.57  -5.14
## [2,]  -8.00 -10.29
## [3,] -12.29 -15.43

B.

a <- matrix(c(1,2,7),3); a
##      [,1]
## [1,]    1
## [2,]    2
## [3,]    7
b <- matrix(c(3,4,8),3); b
##      [,1]
## [1,]    3
## [2,]    4
## [3,]    8

i.

a * b
##      [,1]
## [1,]    3
## [2,]    8
## [3,]   56

ii.

t(a) %*% b
##      [,1]
## [1,]   67

iii.

t(b) %*% (a %*% t(a))
##      [,1] [,2] [,3]
## [1,]   67  134  469

iv.

# (a %*% t(a)) %*% t(b)

It is not possible to calculate this multiplication since the term \(A * A^t\) has dimension \(3 x 3\) while \(B^T\) has dimension \(1x3\) so multiplication between these 2 matrices is not possible.

v.

i3 <- diag(3)
round(((b %*% t(b)) + (a %*% t(a)) - (100 * i3))^(-1),3)
##        [,1]   [,2]  [,3]
## [1,] -0.011  0.071 0.032
## [2,]  0.071 -0.013 0.022
## [3,]  0.032  0.022 0.077

C.

i4 <- diag(4)
q <-  matrix(diag(c(2,3,5,-1)), 4); q
##      [,1] [,2] [,3] [,4]
## [1,]    2    0    0    0
## [2,]    0    3    0    0
## [3,]    0    0    5    0
## [4,]    0    0    0   -1
solve(q) * q - i4
##      [,1] [,2] [,3] [,4]
## [1,]    0    0    0    0
## [2,]    0    0    0    0
## [3,]    0    0    0    0
## [4,]    0    0    0    0

Exercise 3.3

Statistical programming on the R plataform

Faculty of Economics - Course: MINE_008

Author: Nicolás Romero Alfonso & Laura Molina.

Identity card: 1000573650

Copyright 2024

Email: ,

Date: 2024-06-18

Script Name: Exercise 3.3_R_Script_MINE_VIII_Nicolás-Romero_Laura-Molina

Description: Proper syntax exercises to strengthen programming skills in R

Version: 1.0

First steps

rm(list = ls())                                    
objects()
## character(0)
getwd()  
## [1] "C:/Users/nicor/OneDrive - Universidad Externado de Colombia/MINE - 008/PSIS/Scripts/prog_001"
basename(getwd())
## [1] "prog_001"
dirname(getwd())
## [1] "C:/Users/nicor/OneDrive - Universidad Externado de Colombia/MINE - 008/PSIS/Scripts"
cat("/014")     
## /014

A.

PREGUNTAR SI ES DE 4.8 A 0.1 EN LA MISMA CAPA

capas <- array(matrix(seq(4.8, 0.1, length.out = 8), 4, 2, byrow = T), c(4,2,6));capas
## , , 1
## 
##           [,1]     [,2]
## [1,] 4.8000000 4.128571
## [2,] 3.4571429 2.785714
## [3,] 2.1142857 1.442857
## [4,] 0.7714286 0.100000
## 
## , , 2
## 
##           [,1]     [,2]
## [1,] 4.8000000 4.128571
## [2,] 3.4571429 2.785714
## [3,] 2.1142857 1.442857
## [4,] 0.7714286 0.100000
## 
## , , 3
## 
##           [,1]     [,2]
## [1,] 4.8000000 4.128571
## [2,] 3.4571429 2.785714
## [3,] 2.1142857 1.442857
## [4,] 0.7714286 0.100000
## 
## , , 4
## 
##           [,1]     [,2]
## [1,] 4.8000000 4.128571
## [2,] 3.4571429 2.785714
## [3,] 2.1142857 1.442857
## [4,] 0.7714286 0.100000
## 
## , , 5
## 
##           [,1]     [,2]
## [1,] 4.8000000 4.128571
## [2,] 3.4571429 2.785714
## [3,] 2.1142857 1.442857
## [4,] 0.7714286 0.100000
## 
## , , 6
## 
##           [,1]     [,2]
## [1,] 4.8000000 4.128571
## [2,] 3.4571429 2.785714
## [3,] 2.1142857 1.442857
## [4,] 0.7714286 0.100000

B.

nuevas_capas <- capas[c(4,1),2, ]; nuevas_capas
##          [,1]     [,2]     [,3]     [,4]     [,5]     [,6]
## [1,] 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000
## [2,] 4.128571 4.128571 4.128571 4.128571 4.128571 4.128571

C.

array(rep(nuevas_capas[2, ],4), c(2, 2, 2, 3))
## , , 1, 1
## 
##          [,1]     [,2]
## [1,] 4.128571 4.128571
## [2,] 4.128571 4.128571
## 
## , , 2, 1
## 
##          [,1]     [,2]
## [1,] 4.128571 4.128571
## [2,] 4.128571 4.128571
## 
## , , 1, 2
## 
##          [,1]     [,2]
## [1,] 4.128571 4.128571
## [2,] 4.128571 4.128571
## 
## , , 2, 2
## 
##          [,1]     [,2]
## [1,] 4.128571 4.128571
## [2,] 4.128571 4.128571
## 
## , , 1, 3
## 
##          [,1]     [,2]
## [1,] 4.128571 4.128571
## [2,] 4.128571 4.128571
## 
## , , 2, 3
## 
##          [,1]     [,2]
## [1,] 4.128571 4.128571
## [2,] 4.128571 4.128571

D.

nueva_capa_2 <- capas[ , , -6];nueva_capa_2
## , , 1
## 
##           [,1]     [,2]
## [1,] 4.8000000 4.128571
## [2,] 3.4571429 2.785714
## [3,] 2.1142857 1.442857
## [4,] 0.7714286 0.100000
## 
## , , 2
## 
##           [,1]     [,2]
## [1,] 4.8000000 4.128571
## [2,] 3.4571429 2.785714
## [3,] 2.1142857 1.442857
## [4,] 0.7714286 0.100000
## 
## , , 3
## 
##           [,1]     [,2]
## [1,] 4.8000000 4.128571
## [2,] 3.4571429 2.785714
## [3,] 2.1142857 1.442857
## [4,] 0.7714286 0.100000
## 
## , , 4
## 
##           [,1]     [,2]
## [1,] 4.8000000 4.128571
## [2,] 3.4571429 2.785714
## [3,] 2.1142857 1.442857
## [4,] 0.7714286 0.100000
## 
## , , 5
## 
##           [,1]     [,2]
## [1,] 4.8000000 4.128571
## [2,] 3.4571429 2.785714
## [3,] 2.1142857 1.442857
## [4,] 0.7714286 0.100000

E.

nueva_capa_2[c(2, 4), 2, c(1, 3 ,5)] <- 99;nueva_capa_2
## , , 1
## 
##           [,1]      [,2]
## [1,] 4.8000000  4.128571
## [2,] 3.4571429 99.000000
## [3,] 2.1142857  1.442857
## [4,] 0.7714286 99.000000
## 
## , , 2
## 
##           [,1]     [,2]
## [1,] 4.8000000 4.128571
## [2,] 3.4571429 2.785714
## [3,] 2.1142857 1.442857
## [4,] 0.7714286 0.100000
## 
## , , 3
## 
##           [,1]      [,2]
## [1,] 4.8000000  4.128571
## [2,] 3.4571429 99.000000
## [3,] 2.1142857  1.442857
## [4,] 0.7714286 99.000000
## 
## , , 4
## 
##           [,1]     [,2]
## [1,] 4.8000000 4.128571
## [2,] 3.4571429 2.785714
## [3,] 2.1142857 1.442857
## [4,] 0.7714286 0.100000
## 
## , , 5
## 
##           [,1]      [,2]
## [1,] 4.8000000  4.128571
## [2,] 3.4571429 99.000000
## [3,] 2.1142857  1.442857
## [4,] 0.7714286 99.000000