Instalamos las librerias adecuadas para los ejercicios

Fijamos el directorio de trabajo donde guardaremos los resultados obtenidos

setwd("C:/Users/irving/Desktop/9no semestre/Series de Tiempo")

Ecuacion de primer grado Se pretende realizar el mismo ejercicio pero con signos diferentes “Sea \(X_t = 5+0.9Y_{t-1}\)” “Sea \(X_t = 5-0.9Y_{t-1}\)”

Para fines del ejercicio se remplazara Xt con Zt

Tiempo = c(0:100) #Definimos la variable tiempo 

Zt1 = rep(NA,101) #Ecuacion con "+"
Zt2 = rep(NA,101) #Ecuacion con "-"

#Parametro X0=10 <Z0=10>
Zt1[1] = 10 
Zt2[1] = 10

Definicion de las ecuaciones

for (i in c(2:101)){ 
  Zt1[i] = 5 + 0.9*Zt1[i-1]
  Zt2[i] = 5 - 0.9*Zt2[i-1]} 

lista = c(1:16, 97:101) 
Tiempo1 = Tiempo[lista] 

Zt1.1=Zt1[lista]
Zt2.1=Zt2[lista]

Obtencion de la tabla para la presentacion HTML

tabla1 = data.frame(Tiempo1, Zt1.1, Zt2.1) 
colnames(tabla1) <- c("Tiempo", "$Z_t = 5+0.9Z_{t-1}$", "$Z_t = 5-0.9Z_{t-1}$")

kable(tabla1, caption = "Dos ejemplos de Ecuaciones Lineales de Primer Orden", 
      format = "pandoc") %>% kable_styling(font_size = 10)
## Warning in kable_styling(., font_size = 10): Please specify format in kable.
## kableExtra can customize either HTML or LaTeX outputs. See
## https://haozhu233.github.io/kableExtra/ for details.
Dos ejemplos de Ecuaciones Lineales de Primer Orden
Tiempo \(Z_t = 5+0.9Z_{t-1}\) \(Z_t = 5-0.9Z_{t-1}\)
0 10.00000 10.0000000
1 14.00000 -4.0000000
2 17.60000 8.6000000
3 20.84000 -2.7400000
4 23.75600 7.4660000
5 26.38040 -1.7194000
6 28.74236 6.5474600
7 30.86812 -0.8927140
8 32.78131 5.8034426
9 34.50318 -0.2230983
10 36.05286 5.2007885
11 37.44758 0.3192903
12 38.70282 4.7126387
13 39.83254 0.7586252
14 40.84928 4.3172373
15 41.76435 1.1144864
96 49.99838 2.6318772
97 49.99854 2.6313105
98 49.99869 2.6318206
99 49.99882 2.6313615
100 49.99894 2.6317747
tabla <- data.frame( Tiempo, Zt1, Zt2)

Grafica de ecuacion en diferencia de primer orden “+”

EQDif1 <- ggplot( data = tabla , aes(x = Tiempo, y = Zt1) )+ 
  geom_line(col="deeppink4") + 
  geom_point(col= "deeppink4") + 
  labs(y=expression(Z[t]))

EQDif1

Visualizacion del comportamiento

EQDif1 + transition_reveal(Zt1)
## `geom_line()`: Each group consists of only one observation.
## i Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## i Do you need to adjust the group aesthetic?

Grafica de ecuacion en diferencia de primer orden “-” EJERCIIO EXAMEN

EQDif1.1 <- ggplot (data = tabla , aes(x = Tiempo, y=Zt2)) + 
  geom_line(col="deepskyblue4") + 
  geom_point(col= "deepskyblue4") + 
  labs(y=expression(Z[t]))

Visualizacion del comportamiento

EQDif1.1 + transition_reveal(Zt2) +
  shadow_wake(wake_length = 0.1, alpha= FALSE) 

Conversion de tabla a excel

write.xlsx(tabla,"EcuacionG1.xlsx")
## Warning in file.create(to[okay]): cannot create file 'EcuacionG1.xlsx', reason
## 'Permission denied'

Complemento ejercicio 2 ecuacion en diferencia segundo orden

“Sea \(X_t = 14.6 + 1.03X_{t-1} - 0.15X_{t-2}\)”

Asuma que el proceso tiene como valores iniciales “\(X_0 = 10\)” y “\(X_1 = 20\)”. Dicho lo anterior, determine la ecuacion que representa la solucion de la ecuacion (2).

t= ts(c(0:100))
Zt = 121.6188299+9.208484*(0.1755^t)-120.826484*(0.8544^t)

tabla_2 <- data.frame( t, Zt)
lista = c(1:16, 97:101) 
t1 = t[lista] 
Zt1.2=Zt[lista]
Tiempo1 = t[lista]

tabla1 = data.frame(Tiempo1, Zt1.2) 

colnames(tabla1) <- c("t", "$Z_t =121.6188299+9.208484(0.1755)^t-120.826484(0.8544)^t$")

kable(tabla1, 
      caption = "Un ejemplo de Ecuación de Segundo Orden", 
      format = "pandoc") %>% 
  kable_styling(font_size = 121.6188299)
## Warning in kable_styling(., font_size = 121.6188299): Please specify format in
## kable. kableExtra can customize either HTML or LaTeX outputs. See
## https://haozhu233.github.io/kableExtra/ for details.
Un ejemplo de Ecuación de Segundo Orden
t \(Z_t =121.6188299+9.208484(0.1755)^t-120.826484(0.8544)^t\)
0 10.00083
1 20.00077
2 33.69920
3 46.30774
4 57.23925
5 66.60698
6 74.61567
7 81.45914
8 87.30636
9 92.30225
10 96.57074
11 100.21775
12 103.33374
13 105.99605
14 108.27073
15 110.21421
96 121.61880
97 121.61880
98 121.61881
99 121.61881
100 121.61881

Informacion de la tabla

head(tabla_2)
##   t       Zt
## 1 0 10.00083
## 2 1 20.00077
## 3 2 33.69920
## 4 3 46.30774
## 5 4 57.23925
## 6 5 66.60698
str(tabla_2)
## 'data.frame':    101 obs. of  2 variables:
##  $ t : Time-Series  from 1 to 101: 0 1 2 3 4 5 6 7 8 9 ...
##  $ Zt: Time-Series  from 1 to 101: 10 20 33.7 46.3 57.2 ...
names(tabla_2)
## [1] "t"  "Zt"

Grafica de la ecuacion

EqDif2 <- ggplot(data = tabla_2, aes(x = t, y=Zt)) + 
  geom_line(col="cyan4") + 
  geom_point(col= "cyan4") + 
  labs(y=expression(Z[t])) 

EqDif2
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

Conversion de las columnas en datos numericos

tabla_2$t2 <- as.numeric(tabla_2$t)
tabla_2$Zt2 <- as.numeric(tabla_2$Zt)
head(tabla_2)
##   t       Zt t2      Zt2
## 1 0 10.00083  0 10.00083
## 2 1 20.00077  1 20.00077
## 3 2 33.69920  2 33.69920
## 4 3 46.30774  3 46.30774
## 5 4 57.23925  4 57.23925
## 6 5 66.60698  5 66.60698
str(tabla_2)
## 'data.frame':    101 obs. of  4 variables:
##  $ t  : Time-Series  from 1 to 101: 0 1 2 3 4 5 6 7 8 9 ...
##  $ Zt : Time-Series  from 1 to 101: 10 20 33.7 46.3 57.2 ...
##  $ t2 : num  0 1 2 3 4 5 6 7 8 9 ...
##  $ Zt2: num  10 20 33.7 46.3 57.2 ...
names(tabla_2)
## [1] "t"   "Zt"  "t2"  "Zt2"

Realizacion de la grafica con datos numericos

EqDif3 <- ggplot(data = tabla_2, aes(x = t2, y=Zt2)) + 
  geom_line(col="red") + 
  geom_point(col= "red") + 
  labs(y=expression(Z[t]))

EqDif3

EqDif3 + transition_reveal(t2) +
  shadow_wake(wake_length = 0.1, alpha= FALSE)

Conversion del dataframe a excel

write.xlsx(tabla_2,"EcuacionG2.xlsx")
## Warning in file.create(to[okay]): cannot create file 'EcuacionG2.xlsx', reason
## 'Permission denied'