## Ejercicio 16 
a<-matrix(data=c(3,7,-4,12,-5,9,10,2,6,13,8,11,15,5,4,1),
          ncol = 4,nrow = 4,byrow = T) ;a
##      [,1] [,2] [,3] [,4]
## [1,]    3    7   -4   12
## [2,]   -5    9   10    2
## [3,]    6   13    8   11
## [4,]   15    5    4    1
v<-c(a[,2]);v
## [1]  7  9 13  5
w<-c(a[2,]);w
## [1] -5  9 10  2

##Ejercicio 17 
a<-matrix(data=c(3,7,-4,12,-5,9,10,2,6,13,8,11,15,5,4,1),
          ncol = 4,nrow = 4,byrow = T) ;a
##      [,1] [,2] [,3] [,4]
## [1,]    3    7   -4   12
## [2,]   -5    9   10    2
## [3,]    6   13    8   11
## [4,]   15    5    4    1
a1<-a[,-1];a1
##      [,1] [,2] [,3]
## [1,]    7   -4   12
## [2,]    9   10    2
## [3,]   13    8   11
## [4,]    5    4    1
b1<-a[-1,];b1
##      [,1] [,2] [,3] [,4]
## [1,]   -5    9   10    2
## [2,]    6   13    8   11
## [3,]   15    5    4    1
c1<-a[-c(3,4),-1];c1
##      [,1] [,2] [,3]
## [1,]    7   -4   12
## [2,]    9   10    2

#Ejercicio 18 
a<-c(2,4,7)
length(a)
## [1] 3
abs(a)
## [1] 2 4 7
b<-c(2,-4,7)
length(b)
## [1] 3
abs(b)
## [1] 2 4 7

##Ejercicio 19 
a<-matrix(data=c(3,7,-4,12,-5,9,10,2,6,13,8,11,15,5,4,1),
          ncol = 4,nrow = 4,byrow = T) ;a
##      [,1] [,2] [,3] [,4]
## [1,]    3    7   -4   12
## [2,]   -5    9   10    2
## [3,]    6   13    8   11
## [4,]   15    5    4    1
##Maximo y minimo por cada columna 
max(a[,1]);min(a[,1])
## [1] 15
## [1] -5
for(i in 1:4) {
  mx<-max(a[,i])
  print(mx)
}
## [1] 15
## [1] 13
## [1] 10
## [1] 12
for(i in 1:4) {
  mn<-min(a[,i])
  print(mn)
}
## [1] -5
## [1] 5
## [1] -4
## [1] 1
##Maximo y minimo por cada fila 
max(a[1,]);min(a[1,])
## [1] 12
## [1] -4
for(i in 1:4) {
  mx<-max(a[i,])
  print(mx)
}
## [1] 12
## [1] 10
## [1] 13
## [1] 15
for(i in 1:4) {
  mn<-min(a[i,])
  print(mn)
}
## [1] -4
## [1] -5
## [1] 6
## [1] 1

##Ejercicio 20 
a<-matrix(data=c(3,7,-4,12,-5,9,10,2,6,13,8,11,15,5,4,1),
          ncol = 4,nrow = 4,byrow = T) ;a
##      [,1] [,2] [,3] [,4]
## [1,]    3    7   -4   12
## [2,]   -5    9   10    2
## [3,]    6   13    8   11
## [4,]   15    5    4    1
##Ordenar cada columna 
ax1<-matrix(sort(a[,1]))
ax2<-matrix(sort(a[,2]))
ax3<-matrix(sort(a[,3]))
ax4<-matrix(sort(a[,4]))
cbind(ax1,ax2,ax3,ax3)
##      [,1] [,2] [,3] [,4]
## [1,]   -5    5   -4   -4
## [2,]    3    7    4    4
## [3,]    6    9    8    8
## [4,]   15   13   10   10
##Ordenar cada fila 
ay1<-(sort(a[1,]));ay1
## [1] -4  3  7 12
ay2<-(sort(a[2,]));ay2
## [1] -5  2  9 10
ay3<-(sort(a[3,]))
ay4<-(sort(a[4,]))
rbind(ay1,ay2,ay3,ay3)
##     [,1] [,2] [,3] [,4]
## ay1   -4    3    7   12
## ay2   -5    2    9   10
## ay3    6    8   11   13
## ay3    6    8   11   13

###Ejercicio 21 
a<-matrix(data=c(1,4,2,2,4,100,7,9,7,3,pi,42),
          ncol = 3,nrow = 4,byrow = T) ;a
##      [,1]     [,2] [,3]
## [1,]    1 4.000000    2
## [2,]    2 4.000000  100
## [3,]    7 9.000000    7
## [4,]    3 3.141593   42
b<-log(a);b
##           [,1]     [,2]      [,3]
## [1,] 0.0000000 1.386294 0.6931472
## [2,] 0.6931472 1.386294 4.6051702
## [3,] 1.9459101 2.197225 1.9459101
## [4,] 1.0986123 1.144730 3.7376696
c<-b[2,];c
## [1] 0.6931472 1.3862944 4.6051702
sum(c)
## [1] 6.684612
e<-a[,1]*b[,2]
max(e)
## [1] 15.38057
a[1,]/b[-4,-c(1,2)]
## [1] 1.442695 0.868589 1.027797

##Ejercicio 22
a<-matrix(data=c(3,-2,1,6,8,-5,7,9,10),
          ncol = 3,nrow = 3,byrow = T) ;a
##      [,1] [,2] [,3]
## [1,]    3   -2    1
## [2,]    6    8   -5
## [3,]    7    9   10
b<-matrix(data=c(6,9,-4,7,5,3,-8,2,1),
          ncol = 3,nrow = 3,byrow = T) ;b
##      [,1] [,2] [,3]
## [1,]    6    9   -4
## [2,]    7    5    3
## [3,]   -8    2    1
c<-matrix(data=c(-7,-5,2,10,6,1,3,-9,8),
          ncol = 3,nrow = 3,byrow = T) ;c
##      [,1] [,2] [,3]
## [1,]   -7   -5    2
## [2,]   10    6    1
## [3,]    3   -9    8
d<-array(c(a,b,c),dim = c(3,3,3));d
## , , 1
## 
##      [,1] [,2] [,3]
## [1,]    3   -2    1
## [2,]    6    8   -5
## [3,]    7    9   10
## 
## , , 2
## 
##      [,1] [,2] [,3]
## [1,]    6    9   -4
## [2,]    7    5    3
## [3,]   -8    2    1
## 
## , , 3
## 
##      [,1] [,2] [,3]
## [1,]   -7   -5    2
## [2,]   10    6    1
## [3,]    3   -9    8
max(d)
## [1] 10
max(d[,,1])
## [1] 10
max(d[,,2])
## [1] 9
max(d[,,3])
## [1] 10

##Ejercicio 23
a<-matrix(data=c(-7,16,4,9),
          ncol = 2,nrow = 2,byrow = T) ;a
##      [,1] [,2]
## [1,]   -7   16
## [2,]    4    9
b<-matrix(data=c(6,-5,12,-2),
          ncol = 2,nrow = 2,byrow = T) ;b
##      [,1] [,2]
## [1,]    6   -5
## [2,]   12   -2
c<-matrix(data=c(-3,-9,6,8),
          ncol = 2,nrow = 2,byrow = T) ;c
##      [,1] [,2]
## [1,]   -3   -9
## [2,]    6    8
a+b+c
##      [,1] [,2]
## [1,]   -4    2
## [2,]   22   15
a-b+c
##      [,1] [,2]
## [1,]  -16   12
## [2,]   -2   19
(a+b)+c
##      [,1] [,2]
## [1,]   -4    2
## [2,]   22   15
a+(b+c)
##      [,1] [,2]
## [1,]   -4    2
## [2,]   22   15

##Ejercicio 24

f<-matrix(data=c(1,2,3,4,5,400,550,700,500,600,2,0.5,0.75,1.5,3),
          ncol=5,nrow = 3, byrow = T, dimnames = list(c("Path segment", 
                                                        "Force (N)",
                                                        "Distance (m)"),c("C1",
                                                                          "C2", "C3", "C4", "C5")));f 
##               C1    C2     C3    C4  C5
## Path segment   1   2.0   3.00   4.0   5
## Force (N)    400 550.0 700.00 500.0 600
## Distance (m)   2   0.5   0.75   1.5   3
#Trabajo*segmento 
t<-f[2,]*f[3,];t
##   C1   C2   C3   C4   C5 
##  800  275  525  750 1800
rbind(f,t)
##               C1    C2     C3    C4   C5
## Path segment   1   2.0   3.00   4.0    5
## Force (N)    400 550.0 700.00 500.0  600
## Distance (m)   2   0.5   0.75   1.5    3
## t            800 275.0 525.00 750.0 1800
#Trabajo total 
sum(t)
## [1] 4150

#Ejercicio 25
w<-matrix(data=c(1,2,3,4,5,5,5.50,6.50,6,6.25,40,43,37,50,45
                 ,1000,1100,1000,1200,1100),
          ncol=5,nrow = 4, byrow = T, dimnames = list(c("Worker", 
                                                        "Hourly wage ($)",
                                                        "Hours worked", "Output (widgets"),c("C1",
                                                                                             "C2", "C3", "C4", "C5")));w 
##                   C1     C2     C3   C4      C5
## Worker             1    2.0    3.0    4    5.00
## Hourly wage ($)    5    5.5    6.5    6    6.25
## Hours worked      40   43.0   37.0   50   45.00
## Output (widgets 1000 1100.0 1000.0 1200 1100.00
##Cuanto gano cada trabajador 
Ganancia<-w[2,]*w[3,];Ganancia
##     C1     C2     C3     C4     C5 
## 200.00 236.50 240.50 300.00 281.25
rbind(w,Ganancia)
##                   C1     C2     C3   C4      C5
## Worker             1    2.0    3.0    4    5.00
## Hourly wage ($)    5    5.5    6.5    6    6.25
## Hours worked      40   43.0   37.0   50   45.00
## Output (widgets 1000 1100.0 1000.0 1200 1100.00
## Ganancia         200  236.5  240.5  300  281.25
##Cuanto se pago en total 
sum(Ganancia)
## [1] 1258.25
##Cuantos widgets se hicieron
sum(w[4,])
## [1] 5400

##Ejercicio 26
##Asumiendo que los dos buzos empiezan en 0,0,0
##Distancia entre el buzo1y el punto inicial 
dis<-sqrt((60^2)+(25)^2+(30)^2);dis
## [1] 71.58911
##Como debe bucear el buzo 1 para llegar al buzo 2 
60-30
## [1] 30
#Debe nadar 30 ft al oeste 
-25+55
## [1] 30
##Debe nadar 30 ft al sur 
30-20
## [1] 10
#Debe subir 10 ft 
## Que tan lejos en linea recta el buzo 1 para llegar al buzo 2 
dis2<-sqrt((30^2+30^2+10^2));dis2
## [1] 43.58899
##Ejercicio 27 
s<-matrix(data=c(1,2,3,4,5,11,7,8,10,9
                 ,1000,800,900,1200,700),
          ncol=5,nrow = 3, byrow = T, dimnames = list(c("Spring", 
                                                        "Force (N)",
                                                        "Spring Constant k (N/m)"),c("C1",
                                                                                     "C2", "C3", "C4", "C5")));s 
##                           C1  C2  C3   C4  C5
## Spring                     1   2   3    4   5
## Force (N)                 11   7   8   10   9
## Spring Constant k (N/m) 1000 800 900 1200 700
x<-s[2,]/s[3,];x
##          C1          C2          C3          C4          C5 
## 0.011000000 0.008750000 0.008888889 0.008333333 0.012857143
rbind(s,x)
##                              C1       C2           C3           C4
## Spring                  1.0e+00 2.00e+00 3.000000e+00 4.000000e+00
## Force (N)               1.1e+01 7.00e+00 8.000000e+00 1.000000e+01
## Spring Constant k (N/m) 1.0e+03 8.00e+02 9.000000e+02 1.200000e+03
## x                       1.1e-02 8.75e-03 8.888889e-03 8.333333e-03
##                                   C5
## Spring                    5.00000000
## Force (N)                 9.00000000
## Spring Constant k (N/m) 700.00000000
## x                         0.01285714
##Potencial 
p<-(s[3,]*x^2)/2;p
##         C1         C2         C3         C4         C5 
## 0.06050000 0.03062500 0.03555556 0.04166667 0.05785714

##Ejercicio 28 
m<-matrix(data=c(1,2,3,4,5,300,550,400,250,500
                 ,5,3,6,3,2, 4,2,5,5,4,6,4,3,4,3),
          ncol=5,nrow = 5, byrow = F, dimnames = list(c("R1",
                                                        "R2","R3", "R4", "R5"),c("Material",
                                                                                 
                                                                                 "Prince($/ton)", "May", "June", "July")));m 
##    Material Prince($/ton) May June July
## R1        1           300   5    4    6
## R2        2           550   3    2    4
## R3        3           400   6    5    3
## R4        4           250   3    5    4
## R5        5           500   2    4    3
##Precio pagado cada mes 
pp<-m[,-c(1,2)]*m[,2];pp
##     May June July
## R1 1500 1200 1800
## R2 1650 1100 2200
## R3 2400 2000 1200
## R4  750 1250 1000
## R5 1000 2000 1500
#Precio pagado en mayo 
sum(pp[,1])
## [1] 7300
##Precio pagado en Junio 
sum(pp[,2])
## [1] 7550
##Precio pagado en Julio 
sum(pp[,3])
## [1] 7700
##Precio de cada material en los tres meses 
pm<-pp[,1]+pp[,2]+pp[,3];pm
##   R1   R2   R3   R4   R5 
## 4500 4950 5600 3000 4500
##Precio de todos los materiales en los tres meses 
sum(pm)
## [1] 22550

##Ejercicio 29 
a<-matrix(data=c(11,5,-9,-4),
          ncol = 2,nrow = 2,byrow = T);a
##      [,1] [,2]
## [1,]   11    5
## [2,]   -9   -4
b<-matrix(data=c(-7,-8,6,2),
          ncol = 2,nrow = 2,byrow = T);b
##      [,1] [,2]
## [1,]   -7   -8
## [2,]    6    2
a%*%b
##      [,1] [,2]
## [1,]  -47  -78
## [2,]   39   64
b%*%a
##      [,1] [,2]
## [1,]   -5   -3
## [2,]   48   22
##Ejercicio 30 
a<-matrix(data=c(3,-2,1,6,8,-5,7,9,10),
          ncol = 3,nrow = 3,byrow = T) ;a
##      [,1] [,2] [,3]
## [1,]    3   -2    1
## [2,]    6    8   -5
## [3,]    7    9   10
b<-matrix(data=c(6,9,-4,7,5,3,-8,2,1),
          ncol = 3,nrow = 3,byrow = T) ;b
##      [,1] [,2] [,3]
## [1,]    6    9   -4
## [2,]    7    5    3
## [3,]   -8    2    1
c<-matrix(data=c(-7,-5,2,10,6,1,3,-9,8),
          ncol = 3,nrow = 3,byrow = T) ;c
##      [,1] [,2] [,3]
## [1,]   -7   -5    2
## [2,]   10    6    1
## [3,]    3   -9    8
a%*%(b+c)
##      [,1] [,2] [,3]
## [1,]  -42  -17   -5
## [2,]  155  147  -25
## [3,]   96   57  112
a%*%b+a%*%c
##      [,1] [,2] [,3]
## [1,]  -42  -17   -5
## [2,]  155  147  -25
## [3,]   96   57  112
a%*%(b%*%c)
##      [,1] [,2] [,3]
## [1,]  167  287 -125
## [2,]  -99 -111  308
## [3,] 1132  562  250
(a%*%b)%*%c
##      [,1] [,2] [,3]
## [1,]  167  287 -125
## [2,]  -99 -111  308
## [3,] 1132  562  250