#Ejercicio 46
a=5;b=6;c=5;d=6
a1<-(a==b)&&((b==c)||(a==c));a1
## [1] FALSE
a2<-(a==b)|((b==c)&(a==c));a2
## [1] FALSE
a1==a2
## [1] TRUE
b1<-(a<b)&((a>c)|(a>d));b1
## [1] FALSE
b2<-(a<b)&(a>c)|((a>b)&(a<d));b2
## [1] FALSE
b1==b2
## [1] TRUE
##Ejercicio 47
y<-function(x){
  y=(exp(1))^(x+1)
  w1=ifelse(x<(-1),y,"Error x es mayor que -1")
  y1=2+cos(pi*x)
  w2=ifelse(x>=(-1) & x<5,y1,"Error x no está en el dominio de la función")
  y3=10*(x-5)+1
  w3=ifelse(x>=5,y3,"Error x es menor que 5")
  return(list(Ecuación1=w1,Ecuación2=w2,Ecuación3=w3))
}
y(-5)
## $Ecuación1
## [1] 0.01831564
## 
## $Ecuación2
## [1] "Error x no está en el dominio de la función"
## 
## $Ecuación3
## [1] "Error x es menor que 5"
y(3)
## $Ecuación1
## [1] "Error x es mayor que -1"
## 
## $Ecuación2
## [1] 1
## 
## $Ecuación3
## [1] "Error x es menor que 5"
y(15)
## $Ecuación1
## [1] "Error x es mayor que -1"
## 
## $Ecuación2
## [1] "Error x no está en el dominio de la función"
## 
## $Ecuación3
## [1] 101
##Ejercicio 48
y<-function(x,y,z){
  w=x*y*z
  ifelse(x<y & z<10,w,"Error") 
}

##Ejercicio 49 
y<-function(k){
  5*k^3
}
sum(y(c(1:10)))
## [1] 15125
y(c(1:10))
##  [1]    5   40  135  320  625 1080 1715 2560 3645 5000
serie=c()
for(k in 1:10){
  serie[k]=5*k^3
}
serie
##  [1]    5   40  135  320  625 1080 1715 2560 3645 5000
sum(serie)
## [1] 15125
##Ejercicio 50 
x<-function(t){
  5*t-10
}
y<-function(t){
  25*t^2-120*t+144
}
plot(x(0:4),y(0:4),type="l")

distancias=c()
for(i in 0:4){
  distancias[i+1]=sqrt((x(i))^2+(y(i))^2)
}
distancias
## [1] 144.34680  49.25444   4.00000  10.29563  64.77654
points(x(2),y(2))

## El tiempo el cual esta más cercano al origen es t=2

##Ejercicio 51
a<-matrix(data=c(3,5,-4,-8,-1,33,-17,6,9),
          ncol = 3,nrow = 3,byrow = T) ;a
##      [,1] [,2] [,3]
## [1,]    3    5   -4
## [2,]   -8   -1   33
## [3,]  -17    6    9
c<-c()
for(i in 1:9){
  c[i]=log(a[i])
}
## Warning in log(a[i]): Se han producido NaNs

## Warning in log(a[i]): Se han producido NaNs

## Warning in log(a[i]): Se han producido NaNs

## Warning in log(a[i]): Se han producido NaNs
b<-matrix(c,ncol=3);b
##          [,1]     [,2]     [,3]
## [1,] 1.098612 1.609438      NaN
## [2,]      NaN      NaN 3.496508
## [3,]      NaN 1.791759 2.197225
for(i in 1){
  b[1,3]=a[1,3]+20
  b[2,1]=a[2,1]+20
  b[2,2]=a[2,2]+20
  b[3,1]=a[3,1]+20
}
b  
##           [,1]      [,2]      [,3]
## [1,]  1.098612  1.609438 16.000000
## [2,] 12.000000 19.000000  3.496508
## [3,]  3.000000  1.791759  2.197225

###Ejercicio 52
sum<-0
i <-1
while (sum <= 2000) {
  print(i)
  i=i+1
  sum = sum + 2^i 
}
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## [1] 7
## [1] 8
## [1] 9
sum
## [1] 2044
i
## [1] 10
w<-function(x) 2^x
sum(w(1:10))
## [1] 2046
## Ejercicio 53 
cantidad<-1000
k=0
while (cantidad <50000){
  k=k+1
  cantidad= cantidad*1.045+1000
}
k
## [1] 26
cantidad
## [1] 50711.32
### Tomaria 26 años 

##Ejercicio 54
volumen<-function(t){
  v=10^9+10^8*(1-exp(1)^(-t/100))-(10^7)*t
  return(v)
}
plot(volumen,xlim = c(0,110))

inicial<-10^9
t=0
while(inicial >= (10^9)/2){
  t=t+1
  inicial=volumen(t)
}
t
## [1] 55
volumen(55)
## [1] 492305019
##Tomaria 55 días 

##Ejercicio 55
s<-function(k){
  s=((-1)^k)*(1/(2*k+1))
}
diferencias=c()
for(i in 0:200){
  diferencias[i]=sum(s(0:i))-pi/4
}
plot(diferencias,col="red")

##Ejercicio 56 
a<-matrix(data=c(0,-8,6,5,-4,3,10,-1,1,15,1,0,20,2,-1),
          ncol = 3,byrow = T) ;a
##      [,1] [,2] [,3]
## [1,]    0   -8    6
## [2,]    5   -4    3
## [3,]   10   -1    1
## [4,]   15    1    0
## [5,]   20    2   -1
plot(x =a[,3],y= a[,1],type="l",ylim=c(-20,20))
lines(x=a[,3],y=a[,2],col="red")

##Ejercicio 57 
plot(function(x) sin(x), xlim=c(0,1))
plot(function(x) x,xlim=c(0,1),add=T,col="darkblue")

plot(function(x) sin(x)-x,xlim=c(0,1))

plot(function(x) (sin(x)-x)/sin(x),xlim=c(0,1))

dx=0.00001
x1=0
y1=0
while (y1<0.05){
  x1=x1+dx
  y1= abs((sin(x1)-x1)/sin(x1))
}
x1
## [1] 0.53842
##Debe ser 0.53842 para que el error este entre el 5%

##Ejercicio 58 
par(mfrow=c(1,1))
plot(function(x) tan(2*x),xlim=c(0,2*pi))

plot(function(x) 2*tan(x)/(1-(tan(x))^2),xlim=c(0,2*pi),col="red")

##Ejercicio 59 
library(rgl)
y<-function(t,b){
  y=1-exp(1)^(b*t)
  plot3d(t,y,b,col=rainbow(100))
}
y(t=rep(seq(0,1,0.1)),b=rep(seq(-3,7,0.1)))
## Warning in b * t: longitud de objeto mayor no es múltiplo de la longitud de
## uno menor

##Ejercicio 60 
gases<-function(v,m,r=286.7,t=293){
  p=m*r*t/v
  plot3d(v,p,m,col=1:3,type="s")
}
gases(v=rep(seq(20,100,1)),m=rep(c(1,3,7)))