##Ejercicio 61 
x<- 1:10
time<-x[-9]
speed<- c(1210, 1866,2301, 2564, 2724, 2881, 2879, 2915, 3010)
plot(x=time, y=speed)
model<- nls(speed~b*(1-exp(1)^(c*time)),start = list(b=3000,c=-1))
summary(model)
## 
## Formula: speed ~ b * (1 - exp(1)^(c * time))
## 
## Parameters:
##     Estimate Std. Error t value Pr(>|t|)    
## b 2996.28869   19.14635  156.49 1.15e-13 ***
## c   -0.49291    0.01134  -43.46 8.91e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 30.9 on 7 degrees of freedom
## 
## Number of iterations to convergence: 5 
## Achieved convergence tolerance: 7.559e-07
curve(2996.28869*(1-exp(1)^(-0.49291*x)),add=T)
##Ejercicio 62
year<- 1990:1994
temperature<- c(18, 19,21,17,20)
df <-data.frame(year,temperature)
##Stem plot
library(ggplot2)
## Registered S3 methods overwritten by 'ggplot2':
##   method         from 
##   [.quosures     rlang
##   c.quosures     rlang
##   print.quosures rlang

p <- ggplot(data=df) + 
  geom_hline(aes(yintercept=0)) +
  geom_segment(aes(year,temperature,xend=year,yend=temperature-temperature)) + 
  geom_point(aes(year,temperature),size=3) 
p

##Barplot
barplot(temperature~year)

##Stairplot
plot(temperature~year,type = "s")

##Ejercicio 63
v<-function(r){(4/3)*pi*r^3}
a<-function(r){4*pi*r^2}
par(mfrow=c(1,2))
plot(v,xlim = c(0.1,100))
plot(a,xlim = c(0.1,100))

par(mfrow=c(1,2))
plot(v,xlim = c(1,10^4))
plot(a,xlim = c(1,10^4))

##Ejercicio 64
#a
x<-seq(25,45,5)
y<-c(5,260,480,745,1100)
plot(x,y)
model<-lm(y~x)
abline(model)

#b
x<-c(2.5,3,3.5,4,4.5,5,5.5,6:10)
y<-c(1500,1220,1050,915,810,745,690,620,520,480,410,390)
plot(x,y)
model<-lm(log10(y)~x)
summary(model)
## 
## Call:
## lm(formula = log10(y) ~ x)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.038203 -0.033347 -0.008348  0.014708  0.082259 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.282514   0.032613  100.65 2.30e-16 ***
## x           -0.075472   0.005332  -14.16 6.09e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.04254 on 10 degrees of freedom
## Multiple R-squared:  0.9525, Adjusted R-squared:  0.9477 
## F-statistic: 200.4 on 1 and 10 DF,  p-value: 6.093e-08
curve(1916.523*10^(-0.075472*x),add=T)

#c
x<-seq(550,750,50)
y<-c(41.2,18.62,8.62,3.92,1.86)
plot(x,y)
model<-lm(log10(y)~x)
summary(model)
## 
## Call:
## lm(formula = log10(y) ~ x)
## 
## Residuals:
##         1         2         3         4         5 
##  0.004768 -0.003403 -0.001129 -0.006604  0.006369 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  5.314e+00  2.613e-02   203.4 2.62e-07 ***
## x           -6.735e-03  3.996e-05  -168.5 4.61e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.006319 on 3 degrees of freedom
## Multiple R-squared:  0.9999, Adjusted R-squared:  0.9999 
## F-statistic: 2.84e+04 on 1 and 3 DF,  p-value: 4.606e-07
curve(206063*10^(-6.735e-03*x),add=T)

##Ejercicio 65
year<-2002:2007
population<-c(10,10.8,11.7,12.7,13.8,14.9)
plot(year,population)
model<-lm(population~year)
model$coefficients
##   (Intercept)          year 
## -1963.5476190     0.9857143
curve(-1963.5476190+ 0.9857143*x,add=T)
#En que año se duplicara
año=20+1963.5476190/0.9857143
points(2012.005,20)

##Ejercicio 67
time<-0:6
temperature<-c(300,150,75,35,12,5,2)
plot(time,temperature)
model<-lm(log10(temperature)~time)
summary(model)
## 
## Call:
## lm(formula = log10(temperature) ~ time)
## 
## Residuals:
##         1         2         3         4         5         6         7 
## -0.074353 -0.008297  0.057758  0.093850 -0.003951 -0.017076 -0.047931 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.55147    0.04347   58.70 2.71e-08 ***
## time        -0.36709    0.01206  -30.45 7.17e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.06379 on 5 degrees of freedom
## Multiple R-squared:  0.9946, Adjusted R-squared:  0.9936 
## F-statistic: 927.2 on 1 and 5 DF,  p-value: 7.167e-07
curve(356.0164*10^(-0.36709*x),add=T)

##Ejercicio 68
a<-0:9
t<-c(130,115,110,90,89,89,95,100, 110,125)
plot(a,t,type="l")
model <- lm(t ~ poly(a,4))
summary(model)
## 
## Call:
## lm(formula = t ~ poly(a, 4))
## 
## Residuals:
##        1        2        3        4        5        6        7        8 
##  0.04545 -1.76573  5.52739 -4.93298 -0.40676  0.44406  2.55536 -0.53904 
##        9       10 
## -1.70746  0.77972 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 105.3000     1.1723  89.825 3.24e-09 ***
## poly(a, 4)1  -6.3305     3.7071  -1.708    0.148    
## poly(a, 4)2  43.7805     3.7071  11.810 7.66e-05 ***
## poly(a, 4)3   0.5938     3.7071   0.160    0.879    
## poly(a, 4)4  -3.1975     3.7071  -0.863    0.428    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.707 on 5 degrees of freedom
## Multiple R-squared:  0.9663, Adjusted R-squared:  0.9393 
## F-statistic: 35.79 on 4 and 5 DF,  p-value: 0.0007146
points(model$fitted.values,type="l",col=2)

##R cuadrado 0.9663

##Ejercicio 70
temperature<-seq(10,90,10)
s<-c(35,35.6,36.25,36.9,37.5,38.1,38.8,39.4,40)
plot(temperature,s)
model<-lm(s~temperature)
summary(model)
## 
## Call:
## lm(formula = s ~ temperature)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.033889 -0.018889  0.001111  0.009444  0.037778 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 3.436e+01  1.749e-02  1965.2  < 2e-16 ***
## temperature 6.283e-02  3.107e-04   202.2 1.91e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.02407 on 7 degrees of freedom
## Multiple R-squared:  0.9998, Adjusted R-squared:  0.9998 
## F-statistic: 4.089e+04 on 1 and 7 DF,  p-value: 1.91e-14
curve(model$coefficients[1]+model$coefficients[2]*x,add=T)

#T=25 =35.93472 
model$coefficients[1]+model$coefficients[2]*25
## (Intercept) 
##    35.93472

##Ejercicio 71
temperature<-seq(5,45,5)
s<-c(1.95,1.7,1.55,1.40,1.30,1.15,1.05,1,0.95)
plot(temperature,s)
model<-lm(s~temperature)
summary(model)
## 
## Call:
## lm(formula = s ~ temperature)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.06639 -0.04389 -0.03389  0.02861  0.12111 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.951389   0.053887   36.21 3.18e-09 ***
## temperature -0.024500   0.001915  -12.79 4.14e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.07418 on 7 degrees of freedom
## Multiple R-squared:  0.959,  Adjusted R-squared:  0.9531 
## F-statistic: 163.6 on 1 and 7 DF,  p-value: 4.135e-06
abline(model)

#T8 
1.951389-0.024500*8
## [1] 1.755389
#T50
1.951389-0.024500*50
## [1] 0.726389

##Ejercicio 72
x<-1:10
y<-c(10,14,16,18,19,20,21,22,23,23)
plot(x,y)
model<-lm(y~log(x))
summary(model)
## 
## Call:
## lm(formula = y ~ log(x))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.23126 -0.16611 -0.00851  0.11077  0.44979 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   9.9123     0.1721   57.59 9.17e-12 ***
## log(x)        5.7518     0.1035   55.57 1.22e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2276 on 8 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9971 
## F-statistic:  3088 on 1 and 8 DF,  p-value: 1.22e-11
curve(9.9123+ 5.7518*log(x),add=T)

##x=1.5
9.9123+ 5.7518*log(1.5)
## [1] 12.24445
#x=11
9.9123+ 5.7518*log(11)
## [1] 23.70451

##Ejercicio 73
x <- seq(-10, 10, length= 30)
y <- x
f<-function(x,y){x^2-2*x*y+4*y^2}
z <- outer(x, y, f)
z[is.na(z)] <- 1
op <- par(bg = "white")
#superficie
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue")

#Contorno
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
data=data.frame(x,y,z)
p <- plot_ly(data = df, x=~x,y=~y, z=~z, type = "contour", colorscale='Jet')
p
##Ejercicio 74
x <- seq(-10, 10, length= 30)
y <- x
f<-function(x,y){-x^2+2*x*y+3*y^2}
z <- outer(x, y, f)
z[is.na(z)] <- 1
op <- par(bg = "white")
#superficie
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "red")

#Contorno
library(plotly)
data=data.frame(x,y,z)
p <- plot_ly(data = df, x=~x,y=~y, z=~z, type = "contour", colorscale='Jet')
p

##Ejercicio 75
x <- seq(-10, 10, length= 30)
y <- x
f<-function(x,y){(x-y^2)*(x-3*y^2)}
z <- outer(x, y, f)
z[is.na(z)] <- 1
op <- par(bg = "white")
#superficie
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue")

#Contorno
library(plotly)
data=data.frame(x,y,z)
p <- plot_ly(data = df, x=~x,y=~y, z=~z, type = "contour", colorscale='Jet')
p
##Ejercicio 76
x <- seq(-1, 1, length= 30)
y <- x
f<-function(x,y){80*exp(1)^-((x-1)^(2))*exp(1)^-(3*(y-1)^2)}
z <- outer(x, y, f)
z[is.na(z)] <- 1
#superficie
persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue")

#Contorno
library(plotly)
data=data.frame(x,y,z)
p <- plot_ly(data = df, x=~x,y=~y, z=~z, type = "contour", colorscale='Jet')
p
## Temperatura en la posicion x=0,y=0
80*exp(1)^-((0-1)^(2))*exp(1)^-(3*(0-1)^2)
## [1] 1.465251