Ejercicio 1

#1
3*4+6
## [1] 18
#2
cos(5)
## [1] 0.2836622
cos(5)*pi/180
## [1] 0.004950839
#3
x<-4
3*sqrt(6+x)
## [1] 9.486833
#4
y<- 5.2

#5
x<-3; y<-4
z= (2*x) - (7*y)
z
## [1] -22
#6

#7
a1 <- c(1, 0, 2, -3) 
a2 <- c(0, 5, 2, 2) 
a3 <- c(1, 2, 3, 4)
a4 <- c(-2, 0, 1, 3) 

A <- rbind(a1, a2, a3, a4)
A
##    [,1] [,2] [,3] [,4]
## a1    1    0    2   -3
## a2    0    5    2    2
## a3    1    2    3    4
## a4   -2    0    1    3
#8
b1 <- c(1,2,3,4)
B <- cbind(b1)
B
##      b1
## [1,]  1
## [2,]  2
## [3,]  3
## [4,]  4
#9
C <- A%*%B
C
##    b1
## a1 -5
## a2 24
## a3 30
## a4 13
#11



#13


x1 <- c(1, 0, 6) 
x2 <- c(1, 2, 3) 
x3 <- c(4, 5, -2)


X <- rbind(x1, x2, x3)
X
##    [,1] [,2] [,3]
## x1    1    0    6
## x2    1    2    3
## x3    4    5   -2
X2 = cbind(x1, x2, x3)
X2
##      x1 x2 x3
## [1,]  1  1  4
## [2,]  0  2  5
## [3,]  6  3 -2
select(c(X2[,2:3]:X2[0:2,]))
## Warning in X2[, 2:3]:X2[0:2, ]: numerical expression has 6 elements: only the
## first used

## Warning in X2[, 2:3]:X2[0:2, ]: numerical expression has 6 elements: only the
## first used
## [1] 1
sub_ma= X[,1:2]: X[2:3,]
## Warning in X[, 1:2]:X[2:3, ]: numerical expression has 6 elements: only the
## first used
## Warning in X[, 1:2]:X[2:3, ]: numerical expression has 6 elements: only the
## first used
#15

X[0:1,]
## [1] 1 0 6
#17

x = c(1:9)
x
## [1] 1 2 3 4 5 6 7 8 9
#19

sm1 <- c(16, 3, 2, 13) 
sm2 <- c(5, 10, 11, 8) 
sm3 <- c(9, 6, 7, 12)
sm4 <- c(4, 15, 14, 1) 

Constante = 34

sm <- rbind(sm1, sm2, sm3, sm4)
sm
##     [,1] [,2] [,3] [,4]
## sm1   16    3    2   13
## sm2    5   10   11    8
## sm3    9    6    7   12
## sm4    4   15   14    1
sum(sm[,1:1])
## [1] 34
sum(sm[,2:2])
## [1] 34
sum(sm[,3:3])
## [1] 34
sum(sm[,4:4])
## [1] 34
sum(sm[1:1,])
## [1] 34
sum(sm[2:2,])
## [1] 34
sum(sm[3:3,])
## [1] 34
sum(sm[4:4,])
## [1] 34
sum(diag(sm))
## [1] 34

Ejercicio 2

#1
w = 2*3+7
w
## [1] 13
#3

y= 10
Y= 100

#Aunque son la misma letra, estas tienen distinciones en la mayuscula y minuscula, fuera de ello tienen asignados numericos distintos, son variables numericas pero con distintos identificadores y valores. 

#5

x = 5.5 
y = -2.6
z = 2*x - 3*y
z
## [1] 18.8
w = 3*y - z + x/y
w
## [1] -28.71538
#7

r = 6.3
s = 5.8

this_is_the_result = r**2 - s**2
this_is_the_result
## [1] 6.05
#9

#This line will not be executed

#11

y1 = 7
y2 = 9
y3 = y1 - y2/3
y3
## [1] 4
y3_2 = y1 - y2 # hay una nota donde dice que el 3 de la ecuacion y3 es un subindice y que no se debe dividir en 3 por lo que se realizo dos veces la formula por que es algo ambigua la explicacion


#13

cost = 175
profit = 25
sale_price = cost + profit
sale_price
## [1] 200
#15

format.short = round(14/9, 4)
format.short
## [1] 1.5556
format.large = round(14/9, 16)
format.large  
## [1] 1.555556
#17




#19

Altura = 5
Base = 7

Area = (Altura*Base)
Area
## [1] 35
Perimetro = 2*(Altura+Base)
Perimetro
## [1] 24
#21

x=4/5
z=14/17


#23

radio=2/3
Area=pi*(radio^2)

#25

doble = as.double(Area)
doble
## [1] 1.396263
is.double(doble)
## [1] TRUE
#27

y= 9
date = 12

Ejercicio 3

#1

sqrt(10)
## [1] 3.162278
#3

cos(45)
## [1] 0.525322
#5

cos (45*(pi/180))
## [1] 0.7071068
#7

atan(1.5)
## [1] 0.9827937
#9

exp(3)
## [1] 20.08554
#11

log10(3.5)
## [1] 0.544068
#12
x= 2.43
round(x, 1)
## [1] 2.4
#13

#remainder

5 %% 4
## [1] 1
4 %% 5
## [1] 4
#quotient
4 %/% 5
## [1] 0
5 %/% 4
## [1] 1
#14

n = -3.6
funcion = sqrt(n**2)
funcion
## [1] 3.6
abs(n)
## [1] 3.6
#15


1.5-2*sqrt((6.7/5))
## [1] -0.8151674
#16

sin(pi)**2 + cos(pi)**2
## [1] 1
#17

log10(0)
## [1] -Inf
#No genera error pero el valor dado es -infinito, ya que en ese valor esta indefinido

#19

Raiz_45=round(sqrt(45), 1)

#21

Seno_45= sin(45)

#23

Tangente_45 = tan(45)

#25

Exponente_pi_medios = exp(pi/2)
Exponente_pi_medios
## [1] 4.810477

Ejercicio 4

#1

w = c(2, 4, -6, 0)

#3

z = (pi/2)*w
z
## [1]  3.141593  6.283185 -9.424778  0.000000
#5

z[1]
## [1] 3.141593
#7

sum(z)
## [1] 0
sum(z[1:4])
## [1] 0
#9

r = c(1:10)
aumento = r + 2.5

#11

v1 = c(9, 3, -2, 5, 0)
v2 = c(1,2,-4)

vn = c(v1,v2)
vn
## [1]  9  3 -2  5  0  1  2 -4
#13

v1 = c(0.2, 1.3, -3.5)
v2 = c(0.5, -2.5, 1.0)
suma = v1 + v2
suma
## [1]  0.7 -1.2 -2.5
anadidos= c(v1 + v2)
anadidos
## [1]  0.7 -1.2 -2.5
#15

v1 = c(0.2, 1.3, -3.5)
v2 = c(0.5, -2.5, 1.0)
multiplicacion = v1*v2
multiplicacion # no arroja ningun error
## [1]  0.10 -3.25 -3.50
#17

v1 = c(0.2, 1.3, -3.5)
v2 = c(0.5, -2.5, 1.0)
division = v1/v2
division
## [1]  0.40 -0.52 -3.50
#19

v1 = c(1,3,5)
v2 = c(3,6)
suma = v1 + v2
## Warning in v1 + v2: longitud de objeto mayor no es múltiplo de la longitud de
## uno menor
suma #no da ningun error ya que toma la longitud mas grande entre los vectores, al mas pequeño le da valores nulos o 0 pensaria yo y queda el mismo valor del vector mas grande en esos espacios 
## [1] 4 9 8
anadidos= c(v1 + v2)
## Warning in v1 + v2: longitud de objeto mayor no es múltiplo de la longitud de
## uno menor
anadidos
## [1] 4 9 8
#21

w = c(0.1, 1.3,-2.4)
escalar = w + 5
escalar
## [1] 5.1 6.3 2.6
#23

w = c(0.1, 1.3,-2.4)
mulp_escalar = 1.5*w
mulp_escalar
## [1]  0.15  1.95 -3.60
#25

w = c(0.1, 1.3,-2.4)
opera_escalar = 3-2*w/5
opera_escalar
## [1] 2.96 2.48 3.96
#27

b = c(0, pi/3, 2*pi/3, pi)
exp(b)
## [1]  1.000000  2.849654  8.120527 23.140693
#29

3**b #sin mensajes de error
## [1]  1.000000  3.159659  9.983445 31.544281
#31

a = c(1,1,1,1)


#33

vd = c(0.35, -1.0, 0.24, 1.30, -0.30)
sort(vd)
## [1] -1.00 -0.30  0.24  0.35  1.30
#35

vr = c(2,4,-3,0,1,5,7)
media = mean(vr)
media
## [1] 2.285714
rango = range(vr)
rango
## [1] -3  7
mediana = median(vr)
mediana
## [1] 2
#37

x = c("r", "s", "t", "u", "v")
n = c(1,0,-2,3,5)
y<-paste(x,'+',n)
y
## [1] "r + 1"  "s + 0"  "t + -2" "u + 3"  "v + 5"
#39



#41

Ejercicio 5

#1

a<-c(3,1,0,3,-2,5)
A<-matrix(a,2)
A
##      [,1] [,2] [,3]
## [1,]    3    0   -2
## [2,]    1    3    5
dim(A)
## [1] 2 3
#3

B<-((3/2)*pi)*A
B
##           [,1]     [,2]      [,3]
## [1,] 14.137167  0.00000 -9.424778
## [2,]  4.712389 14.13717 23.561945
#5
sub_ma= c(B[1,1], B[2,2])
matriz= matrix(sub_ma)

#7
length(matriz)
## [1] 2
#9

sumaT= sum(B[,0:1]) + sum(B[,2:2]) + sum(B[,3:3])
sumaT
## [1] 47.12389
max(B)
## [1] 23.56194
min(B)
## [1] -9.424778
#11

a<-c(1,7,3,2,5,1,0,-3,1)
b<-c(1,3,2,3,5,3,-2,7,0)
R<-matrix(a,3)
S<-matrix(b,3)
R
##      [,1] [,2] [,3]
## [1,]    1    2    0
## [2,]    7    5   -3
## [3,]    3    1    1
S
##      [,1] [,2] [,3]
## [1,]    1    3   -2
## [2,]    3    5    7
## [3,]    2    3    0
A<-R+S
B<-R-S
A
##      [,1] [,2] [,3]
## [1,]    2    5   -2
## [2,]   10   10    4
## [3,]    5    4    1
B
##      [,1] [,2] [,3]
## [1,]    0   -1    2
## [2,]    4    0  -10
## [3,]    1   -2    1
#13

De<-R/S
De
##          [,1]      [,2]       [,3]
## [1,] 1.000000 0.6666667  0.0000000
## [2,] 2.333333 1.0000000 -0.4285714
## [3,] 1.500000 0.3333333        Inf
#15
x<-c(1,2,-3,5,-2,3,5,-2,0,6,2,4,1,2,1,4)
X<-matrix(x,4)
X
##      [,1] [,2] [,3] [,4]
## [1,]    1   -2    0    1
## [2,]    2    3    6    2
## [3,]   -3    5    2    1
## [4,]    5   -2    4    4
M<-X+5
M
##      [,1] [,2] [,3] [,4]
## [1,]    6    3    5    6
## [2,]    7    8   11    7
## [3,]    2   10    7    6
## [4,]   10    3    9    9
#17

y = X*-3
y
##      [,1] [,2] [,3] [,4]
## [1,]   -3    6    0   -3
## [2,]   -6   -9  -18   -6
## [3,]    9  -15   -6   -3
## [4,]  -15    6  -12  -12
#19

-3*X/2.4+5.5
##       [,1]  [,2] [,3] [,4]
## [1,]  4.25  8.00  5.5 4.25
## [2,]  3.00  1.75 -2.0 3.00
## [3,]  9.25 -0.75  3.0 4.25
## [4,] -0.75  8.00  0.5 0.50
#21

B = c(pi/3, (2*pi)/3, (2*pi)/3, pi)
Bb=matrix(B,2)
Bb
##          [,1]     [,2]
## [1,] 1.047198 2.094395
## [2,] 2.094395 3.141593
sqrt(Bb)
##          [,1]     [,2]
## [1,] 1.023327 1.447203
## [2,] 1.447203 1.772454
#23

exp(1)^B
## [1]  2.849654  8.120527  8.120527 23.140693
#25

log(B)
## [1] 0.0461176 0.7392648 0.7392648 1.1447299
#27

exp(4)^B
## [1]     65.94297   4348.47466   4348.47466 286751.31314
#29

B^(4)
## [1]  1.202581 19.241302 19.241302 97.409091
#31

cero = c(0, 0, 0, 0, 0, 0)
M_cero=matrix(cero,2)
M_cero
##      [,1] [,2] [,3]
## [1,]    0    0    0
## [2,]    0    0    0
#33

matrix(1,nrow = 4,ncol = 4)
##      [,1] [,2] [,3] [,4]
## [1,]    1    1    1    1
## [2,]    1    1    1    1
## [3,]    1    1    1    1
## [4,]    1    1    1    1
#35
cero = c(1, 0 , 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
M_cero=matrix(cero,4)
M_cero
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    0    1    0    0
## [3,]    0    0    1    0
## [4,]    0    0    0    1
#36
a<-c(1,2,1,2,2,5,3,3,-3,2,7,-1,0,-3,-2,3)
C<-matrix(a,4)
C
##      [,1] [,2] [,3] [,4]
## [1,]    1    2   -3    0
## [2,]    2    5    2   -3
## [3,]    1    3    7   -2
## [4,]    2    3   -1    3
t(C)
##      [,1] [,2] [,3] [,4]
## [1,]    1    2    1    2
## [2,]    2    5    3    3
## [3,]   -3    2    7   -1
## [4,]    0   -3   -2    3
#37
sum_c= C+C
sum_c
##      [,1] [,2] [,3] [,4]
## [1,]    2    4   -6    0
## [2,]    4   10    4   -6
## [3,]    2    6   14   -4
## [4,]    4    6   -2    6
#39

sup= c(C[,1], C[1,2],C[2,2],C[3,2], C[1,3],C[2,3],C[1,4])
infe= c(C[,4], C[4,3],C[3,3],C[2,3], C[3,2],C[3,2],C[4,1])

#41
C_1<-solve(C)

#43



#45



#47

a<-c(1,2,1,2,2,5,3,3,-3,2,7,-1,0,-3,-2, 3, 3,-2, 5, 8, -8, 5, 8, 7, 8)
C<-matrix(a,5)
C
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1    5    7    3   -8
## [2,]    2    3   -1    3    5
## [3,]    1    3    0   -2    8
## [4,]    2   -3   -3    5    7
## [5,]    2    2   -2    8    8

Ejercicio 6

#1
#Example 8 
Cost = 200
sale_price = 250
profit = Cost - sale_price


#3

RectanguloArea = c(a=3,b=6)
#Area de un rectangulo
RectanguloArea[1]*RectanguloArea[2]
##  a 
## 18
RectanguloArea = c(a=2.5, b=5.5)
#Area de un rectangulo
RectanguloArea[1]*RectanguloArea[2]
##     a 
## 13.75
#5

almacen1 = c()
almacen2 = c()

for(n in 1:4){
  almacen1[n] = print(n**2)
}
## [1] 1
## [1] 4
## [1] 9
## [1] 16
for(m in 1:4){
  almacen2[m] = print(n**2)
}
## [1] 16
## [1] 16
## [1] 16
## [1] 16
almacen_f= almacen2 - almacen1
almacen_f
## [1] 15 12  7  0
#7

price <- numeric()
for (items in c(3,9)){
  if (items<5){
    price[items]<-print(items*130)
  }
if (items>5){
    price[items]<-print(items*160)
  }
}
## [1] 390
## [1] 1440
price
## [1]   NA   NA  390   NA   NA   NA   NA   NA 1440

Ejercicio 7

#1

x = c(1:7)
y = c(10,15, 23, 43, 30, 10, 12)
plot(x, y)

#3


x = -6:6
y = 2*(x**3) + 5

plot(x, y, xlab = "Eje X", ylab = "Eje Y", main = "Grafico")

#5

y = 2*sin(x/3)
z = 2*cos(x/3)
x= seq(0, 3*pi, pi/4)

plot(x, y, type = "o", col = "blue", pch = "o", ylab = "y", lty = 1, xlab ="Eje X" , main = "grafico Y vs Z")
points(x, z, col = "dark red", pch = "+")
lines(x, z, col = "dark red", lty = 3)
legend (8,2, legend = c ("y", "z"), col = c("blue", "red"),pch = c ("o", "*", "+"),lty=c(1,2),ncol = 1)

#7

##Exercise 1

#2
cos(5)
## [1] 0.2836622
#4
y<-5.2
y
## [1] 5.2
#6##############################################
#8
b<-c(1,2,3,4)
b<-t(t(b))
b
##      [,1]
## [1,]    1
## [2,]    2
## [3,]    3
## [4,]    4
#10
a<-c(5,1)
b<-c(2,3)
d<-c(3,-1)
e<-matrix(c(a,b,d),2)
e
##      [,1] [,2] [,3]
## [1,]    5    2    3
## [2,]    1    3   -1
print('..............')
## [1] ".............."
e<-t(matrix(c(e[1,]/5,e[2,]),3))
e
##      [,1] [,2] [,3]
## [1,]    1  0.4  0.6
## [2,]    1  3.0 -1.0
print('..............')
## [1] ".............."
e<-t(matrix(c(e[1,],e[2,]-e[1,]),3))
e
##      [,1] [,2] [,3]
## [1,]    1  0.4  0.6
## [2,]    0  2.6 -1.6
print('..............')
## [1] ".............."
e<-t(matrix(c(e[1,],e[2,]/2.6),3))
e
##      [,1] [,2]       [,3]
## [1,]    1  0.4  0.6000000
## [2,]    0  1.0 -0.6153846
print('..............')
## [1] ".............."
d<-c(0,"x2 =",e[2,3])
m<-c('x1',"0.4 x2",0.6)
f<-t(matrix(c(m,d),3))
f
##      [,1] [,2]     [,3]                
## [1,] "x1" "0.4 x2" "0.6"               
## [2,] "0"  "x2 ="   "-0.615384615384615"
print('..............')
## [1] ".............."
d<-c("x1 =",0.6-(e[1,2]*e[2,3]))
d
## [1] "x1 ="              "0.846153846153846"
f[2,2:3]
## [1] "x2 ="               "-0.615384615384615"
#12

b<-c(1,1,4)
a<-c(0,2,5)
d<-c(6,3,-2)
f<-matrix(c(b,a,d),3)
f
##      [,1] [,2] [,3]
## [1,]    1    0    6
## [2,]    1    2    3
## [3,]    4    5   -2
#14
f[1:3,2]
## [1] 0 2 5
#16
f[1,3]
## [1] 6
#17
x<-sequence(9)
x
## [1] 1 2 3 4 5 6 7 8 9
#18
plot(x,((x^3)-2),type = 'l')

##Exercise 2

#2
a<-4
b<--10
c<-3.2
#4
x=5.5
y=-2.6
z=2*x-3*y
z
## [1] 18.8
#6
r=6.3
s=5.8
d=(r+s)-(r*s)
d
## [1] -24.44
#8
width<-1.5
Width<-2.0
WIDTH<-4.5
width
## [1] 1.5
Width
## [1] 2
WIDTH
## [1] 4.5
#Las variables son diferentes
#10
s<-3.5    #Se le asigna un valor a la variable s 
#12
#y=(2*m)-5 
#El error es debido a que la variable m no esta definida   
#14
centigrade=28
fahrenheit=(centigrade*9/5)+32
fahrenheit
## [1] 82.4
#16
#18
#20
radio<-6.45
perimetro<-2*pi*radio
perimetro
## [1] 40.52655
area<-pi*(radio^2)
area
## [1] 130.6981
#21
x<-4/5
z<-14/17
#22
b<-2*x-z
b  
## [1] 0.7764706
#24
radio<-2/3
vol<-(4/3)*pi*(radio^3)
#26

##Exercise 3

#2
factorial(7)
## [1] 5040
#3
cos(45)
## [1] 0.525322
#4
rad<-45
deg<-rad*pi/180
cos(deg)
## [1] 0.7071068
#6
rad<-45
deg<-rad*pi/180
tan(deg)
## [1] 1
#8
a<-(3/2)*pi
a
## [1] 4.712389
tan(a)
## [1] 5.443746e+15
#No se presenta ningun error ya que R esta redondeando el valor de pi, por lo que se toma 
#un valor muy cercano a la asintota formada en  tan(x) para x=(3/2)*pi, y no se llega a infinito
exp(1)
## [1] 2.718282
#10
log(3.5,base = exp(1))
## [1] 1.252763
#12
round(2.43,1)
## [1] 2.4
#14
abs(-3.6)
## [1] 3.6
#16
((sin(pi))^2)+((cos(pi))^2)
## [1] 1
#18
x=(3/2)*pi
y=2*pi
2*sin(x)*cos(y)
## [1] -2
#20
sqrt(45)
## [1] 6.708204
#22
#24

##Exercise 4

#1
w<-c(2,4,-6,0)
#2
w[2]
## [1] 4
#3
z=(pi/2)*w
z
## [1]  3.141593  6.283185 -9.424778  0.000000
#4
z[4]
## [1] 0
#6
length(z)
## [1] 4
#8
min(z) #minimo
## [1] -9.424778
max(z) #maximo
## [1] 6.283185
#10
m<-NULL
for (i in sequence(10)){
  m[i]<-i*10
}
m
##  [1]  10  20  30  40  50  60  70  80  90 100
#12
a<-c(9,3,-2,5,0)
d<-c(a,4)
d
## [1]  9  3 -2  5  0  4
#13
a<-c(0.2,1.3,-3.5)
b<-c(0.5,-2.5,1.0)
d<-c(a,b)
d
## [1]  0.2  1.3 -3.5  0.5 -2.5  1.0
#14
a<-d[1:3]
b<-d[4:6]
a
## [1]  0.2  1.3 -3.5
b
## [1]  0.5 -2.5  1.0
#16
a*b
## [1]  0.10 -3.25 -3.50
#18
d<-0
k<-a*b
for (i in k){
 d<-d+i 
}
d
## [1] -6.65
#20
#a<-c(1,3,5)
#b<-c(3,6)
#k<-a-b
# El error se presenta porque a y b no tienen la misma longitud, 
#a tiene 3 elementos y b tiene unicamente 2
#21
w<-c(0.1,1.3,-2.4)
x<-5+w
x
## [1] 5.1 6.3 2.6
#22
y<--2-w
y
## [1] -2.1 -3.3  0.4
#24
z<-w/10
z
## [1]  0.01  0.13 -0.24
#26
b<-c(0,pi/3,(2/3)*pi,pi)
b
## [1] 0.000000 1.047198 2.094395 3.141593
sin(b)
## [1] 0.000000e+00 8.660254e-01 8.660254e-01 1.224606e-16
cos(b)
## [1]  1.0  0.5 -0.5 -1.0
tan(b)
## [1]  0.000000e+00  1.732051e+00 -1.732051e+00 -1.224647e-16
#28
m<-sqrt(b)
m
## [1] 0.000000 1.023327 1.447203 1.772454
#30
b<-c(0,pi/3,(2/3)*pi,pi)
f<-NULL
for (i in b){
  f[i+1]<-(3^i)
}
f
## [1]  1.000000  3.159659  9.983445 31.544281
#32
a<-c(0,0,0,0,0,0)
#34
z<-sample.int(x,5)
z
## [1] 4 5 2 1 3
#36
x<-c("r","s","t","u","v")
x
## [1] "r" "s" "t" "u" "v"
#37
m<-c(1,0,-2,3,5)
y<-paste(x,'+',m)
v<-unlist(strsplit(y[3],'+'))
v<-paste(v[1],v[5],v[6])
y<-c(y[1:2],v,y[4:5])
y
## [1] "r + 1" "s + 0" "t - 2" "u + 3" "v + 5"
#38
y[3]
## [1] "t - 2"
#40
m<-NULL
n<-NULL
for (i in sequence(4)){
  m[i]<-paste(x[i],'*(',y[i],')+')
  n[i]<-paste('(',y[i],')*',x[i],'+')
}
m<-c(m,paste(x[5],'*(',y[5],')'))
n<-c(n,paste('(',y[5],')*',x[5]))
m<-paste(m[1],m[2],m[3],m[4],m[5])
n<-paste(n[1],n[2],n[3],n[4],n[5])
m
## [1] "r *( r + 1 )+ s *( s + 0 )+ t *( t - 2 )+ u *( u + 3 )+ v *( v + 5 )"
n
## [1] "( r + 1 )* r + ( s + 0 )* s + ( t - 2 )* t + ( u + 3 )* u + ( v + 5 )* v"
#El resultado es el mismo porque el producto punto es conmutativo

##Exercise 5

#1
a<-c(3,1,0,3,-2,5)
A<-matrix(a,2)
A
##      [,1] [,2] [,3]
## [1,]    3    0   -2
## [2,]    1    3    5
dim(A)
## [1] 2 3
#2
A[2,2]
## [1] 3
#3
B<-((3/2)*pi)*A
B
##           [,1]     [,2]      [,3]
## [1,] 14.137167  0.00000 -9.424778
## [2,]  4.712389 14.13717 23.561945
#4
B[1,3]
## [1] -9.424778
#6
dim(B)
## [1] 2 3
#8
n<-dim(B)
elem<-n[1]*n[2]
elem
## [1] 6
#10
a<-c(1,3,0,-4)
b<-c(5,3,1,0)
d<-c(2,2,-1,1)
matrix(c(a,b,d),3)
##      [,1] [,2] [,3] [,4]
## [1,]    1   -4    1    2
## [2,]    3    5    0   -1
## [3,]    0    3    2    1
#11
a<-c(1,7,3,2,5,1,0,-3,1)
b<-c(1,3,2,3,5,3,-2,7,0)
R<-matrix(a,3)
S<-matrix(b,3)
R
##      [,1] [,2] [,3]
## [1,]    1    2    0
## [2,]    7    5   -3
## [3,]    3    1    1
S
##      [,1] [,2] [,3]
## [1,]    1    3   -2
## [2,]    3    5    7
## [3,]    2    3    0
A<-R+S
B<-R-S
A
##      [,1] [,2] [,3]
## [1,]    2    5   -2
## [2,]   10   10    4
## [3,]    5    4    1
B
##      [,1] [,2] [,3]
## [1,]    0   -1    2
## [2,]    4    0  -10
## [3,]    1   -2    1
#12
Me<-S*R
Me
##      [,1] [,2] [,3]
## [1,]    1    6    0
## [2,]   21   25  -21
## [3,]    6    3    0
#13
De<-R/S
De
##          [,1]      [,2]       [,3]
## [1,] 1.000000 0.6666667  0.0000000
## [2,] 2.333333 1.0000000 -0.4285714
## [3,] 1.500000 0.3333333        Inf
#14
Mm<-R%*%S
Mm
##      [,1] [,2] [,3]
## [1,]    7   13   12
## [2,]   16   37   21
## [3,]    8   17    1
#15
x<-c(1,2,-3,5,-2,3,5,-2,0,6,2,4,1,2,1,4)
X<-matrix(x,4)
X
##      [,1] [,2] [,3] [,4]
## [1,]    1   -2    0    1
## [2,]    2    3    6    2
## [3,]   -3    5    2    1
## [4,]    5   -2    4    4
M<-X+5
M
##      [,1] [,2] [,3] [,4]
## [1,]    6    3    5    6
## [2,]    7    8   11    7
## [3,]    2   10    7    6
## [4,]   10    3    9    9
#16
N<-X-3
N
##      [,1] [,2] [,3] [,4]
## [1,]   -2   -5   -3   -2
## [2,]   -1    0    3   -1
## [3,]   -6    2   -1   -2
## [4,]    2   -5    1    1
#18
M<-X/2
M
##      [,1] [,2] [,3] [,4]
## [1,]  0.5 -1.0    0  0.5
## [2,]  1.0  1.5    3  1.0
## [3,] -1.5  2.5    1  0.5
## [4,]  2.5 -1.0    2  2.0
#20
B<-matrix(c(pi/3,(2/3)*pi,(2/3)*pi,pi),2)
B
##          [,1]     [,2]
## [1,] 1.047198 2.094395
## [2,] 2.094395 3.141593
sin(B)
##           [,1]         [,2]
## [1,] 0.8660254 8.660254e-01
## [2,] 0.8660254 1.224606e-16
cos(B)
##      [,1] [,2]
## [1,]  0.5 -0.5
## [2,] -0.5 -1.0
tan(B)
##           [,1]          [,2]
## [1,]  1.732051 -1.732051e+00
## [2,] -1.732051 -1.224647e-16
#22
sqrt(B)
##          [,1]     [,2]
## [1,] 1.023327 1.447203
## [2,] 1.447203 1.772454
#23
exp(1)^B
##          [,1]      [,2]
## [1,] 2.849654  8.120527
## [2,] 8.120527 23.140693
#24
expm(B)
## 2 x 2 Matrix of class "dsyMatrix"
##         [,1]    [,2]
## [1,] 23.9028 37.4119
## [2,] 37.4119 61.3147
#26
#B<-matrix(c(pi/3,(2/3)*pi,(2/3)*pi,pi),2)
#logm(B)
#28
4^B
##           [,1]     [,2]
## [1,]  4.270471 18.23692
## [2,] 18.236920 77.88023
#30
matrix(1,nrow = 2,ncol = 3)
##      [,1] [,2] [,3]
## [1,]    1    1    1
## [2,]    1    1    1
#32
matrix(c(1,0,0,1,0,0),2)
##      [,1] [,2] [,3]
## [1,]    1    0    0
## [2,]    0    1    0
#34
matrix(0,nrow = 4,ncol = 4)
##      [,1] [,2] [,3] [,4]
## [1,]    0    0    0    0
## [2,]    0    0    0    0
## [3,]    0    0    0    0
## [4,]    0    0    0    0
#36
a<-c(1,2,1,2,2,5,3,3,-3,2,7,-1,0,-3,-2,3)
C<-matrix(a,4)
t(C)
##      [,1] [,2] [,3] [,4]
## [1,]    1    2    1    2
## [2,]    2    5    3    3
## [3,]   -3    2    7   -1
## [4,]    0   -3   -2    3
#38
diag(C)
## [1] 1 5 7 3
#40
det(C)
## [1] -13
sum(diag(C))
## [1] 16
#Si se obtienen escalares, porque el determinante es un numero que caracteriza a una matriz y por ende se le atribuyen varias propiedades
#La traza de la matriz es la suma de los elentos de la diagonal, por ende se obtiene un escalar
#41
C_1<-solve(C)
#42
D<-C%*%C_1
D
##               [,1]         [,2] [,3]          [,4]
## [1,]  1.000000e+00 1.387779e-16    0  5.551115e-17
## [2,] -1.776357e-15 1.000000e+00    0  3.330669e-16
## [3,]  0.000000e+00 0.000000e+00    1 -5.551115e-17
## [4,] -8.881784e-16 0.000000e+00    0  1.000000e+00
#Se obtiene la matriz identidad, sin embargo no se observa asi, porque al obtener la inversa y multiplicarlar por la original, se redondearon algunos valores, aqui se observa la matriz redondeada a enteros:
D<-round(D,2)
D
##      [,1] [,2] [,3] [,4]
## [1,]    1    0    0    0
## [2,]    0    1    0    0
## [3,]    0    0    1    0
## [4,]    0    0    0    1
#44
eigen(C)
## eigen() decomposition
## $values
## [1]  8.19439889+0.000000i  3.93791318+2.661524i  3.93791318-2.661524i
## [4] -0.07022524+0.000000i
## 
## $vectors
##                [,1]                 [,2]                 [,3]           [,4]
## [1,]  0.24942346+0i 0.1235076+0.3224730i 0.1235076-0.3224730i  0.88639724+0i
## [2,] -0.41481971+0i 0.2577553+0.3723022i 0.2577553-0.3723022i -0.44089112+0i
## [3,] -0.87469708+0i 0.3369753-0.1771706i 0.3369753+0.1771706i  0.02228749+0i
## [4,]  0.02485078+0i 0.7285386+0.0000000i 0.7285386+0.0000000i -0.13934927+0i
#46
rankMatrix(C)[1]
## [1] 4
#48
#B<-magic(7)
#B
#a<-NULL
#b<-NULL
#for (i in sequence(7)){
  #a[i]<-sum(B[i,])
  #b[i]<-sum(B[,i])
#}
#a
#b
#a y b son las sumas de cada fila y columna de la matriz B

##Exercise 6

#2
# FUNCTION: volume(r)
#Este codigo obtiene el volumen de una esfera de radio 2
volume.m<-(4/3)*pi*(2^3)
#4 example9
#este codigo genera un vector x tal que: x(n)=n^3
x<-NULL
for (n in sequence(7)){
 x[n]<-n^3 
}
x
## [1]   1   8  27  64 125 216 343
#6 example11
#este codigo genera un bucle, hasta que tol sea 
tol=0
n=3
while (tol<1.5) {
  n=n+1
  tol=tol+0.1
}
n
## [1] 18
tol
## [1] 1.5
#8 price2(items)
price2<-0
for (items in c(2,4,6)){
  if (items<3){
    price2[items-1]<-items*130
  }else if(items<5){
    price2[items-2]<-items*160
  }else if(items>5){
    price2[items-3]<-items*200
  }
} 
price2
## [1]  260  640 1200

##Exercises 7

#1
x<-sequence(7)
y<-c(10,15,23,43,30,10,12)
plot(x,y,title('Exercise 2'),xlab = 'axisx',ylab = 'axisy')

#3
x<-(-6:6)
plot(x,y=(2*(x^3))+5,main = 'Exercise 3',xlab = 'x',ylab = 'y')

#4
x<-(-6:6)
plot(x,y=(2*(x^3))+5,main = 'Exercise 3',xlab = 'x',ylab = 'y',type='b', col='blue',pch=16,cex=1.5)

#6
x=sequence(10)
plot(x,2*(x^3)-4,type='b',col='green')

plot(x,x+1,type = 'b',col='red')

plot(x,2-sqrt(x),type = 'b',col='blue')

plot(x,(x^2)+3,type = 'b',col='yellow')

x<-(1:10)
y<-(1:10)
a<-function(x,y){
  return(2*sin(x*y))
}
z<-outer(x,y,a)

op<-par(bg ='white')
persp(x,y,z,theta = 50,phi = 30,expand = 0.5,col = 'lightblue')

#x<-seq(0,4,length=25)
#y<-seq(0,4,length=25)
#a<-c(0.1,0.2,0.5,0.4,0.1,0.2,0.8,0.9,0.4,0.3,0.5,0.5,0.9,0.5,0.4,0.7,0.6,0.4,0.7,0.6,0.3,0.3,0.4,0.9,0.8)
#matrix(a,5)

#z<-outer(x,y,x)
#op<-par(bg='white')
#persp(x,y,z)