Ejercicio 1

Sea \(f(x)=\sqrt{x}-\cos x\). Usa el método de la bisección para encontrar \(x\in [0,1]\) tal que \(f(x)=0\).

f_1 <- function(x){sqrt(x)-cos(x)}

x_1 <- seq(from=-1, to=2, by=0.1)
y_1 <- f_1(x_1)
## Warning in sqrt(x): Se han producido NaNs
graf_1 <- ggplot()+
  geom_vline(xintercept = 0, linetype="dashed")+ #eje x
  geom_hline(yintercept = 0, linetype="dashed")+ #eje y
  geom_line(aes(x=x_1, y=y_1), color="blue", size=1)+
  #coord_fixed(ratio = 1)+ # misma escala en los ejes
  labs(x="x", y="f(x)", title="Método de bisección")+
  theme_bw()

#plot(graf_1)

ggplotly(graf_1)
metodo_biseccion(f_1, 0, 1, 10^(-2),100)
## $aprox
## [1] 0.5000000 0.7500000 0.6250000 0.6875000 0.6562500 0.6406250 0.6484375
## 
## $precision
## [1] 0.0078125
## 
## $iteraciones
## [1] 7
bisect(f_1,0,1,100)
## $root
## [1] 0.6417144
## 
## $f.root
## [1] -2.220446e-16
## 
## $iter
## [1] 54
## 
## $estim.prec
## [1] 1.110223e-16

Ejercicio 2

Usa el método de la bisección para encontrar una raíz con una precisión de \(10^{-2}\) para \(x^3-7x^2+14x-6=0\) en cada intervalo.

\[\begin{equation} a) [0,1]\qquad\qquad b) [1, 3.2]\qquad\qquad c)[3.2, 4] \end{equation}\]

f_2 <- function(x){x^3-7*x^2+14*x-6}

x_2 <- seq(from= -0.5, to=6, by=0.1)
y_2 <- f_2(x_2)

graf_2 <- ggplot()+
  geom_vline(xintercept = 0, linetype="dashed")+ #eje x
  geom_hline(yintercept = 0, linetype="dashed")+ #eje y
  geom_line(aes(x=x_2, y=y_2), color="blue", size=1)+
  #coord_fixed(ratio = 1)+ # misma escala en los ejes
  labs(x="x", y="f(x)", title="Método de bisección ejercicio 2")+
  theme_bw()

#plot(graf_1)

ggplotly(graf_2)

a)[0,1]

metodo_biseccion(f_2, 0, 1, 10^(-2),100)
## $aprox
## [1] 0.5000000 0.7500000 0.6250000 0.5625000 0.5937500 0.5781250 0.5859375
## 
## $precision
## [1] 0.0078125
## 
## $iteraciones
## [1] 7
bisect(f_2, 0, 1)
## $root
## [1] 0.5857864
## 
## $f.root
## [1] -8.881784e-16
## 
## $iter
## [1] 54
## 
## $estim.prec
## [1] 1.110223e-16
  1. [1, 3.2]
metodo_biseccion(f_2, 1, 3.2, 10^(-2),100)
## $aprox
## [1] 2.100000 2.650000 2.925000 3.062500 2.993750 3.028125 3.010938 3.002344
## 
## $precision
## [1] 0.00859375
## 
## $iteraciones
## [1] 8
bisect(f_2, 1, 3.2)
## $root
## [1] 3
## 
## $f.root
## [1] 7.105427e-15
## 
## $iter
## [1] 54
## 
## $estim.prec
## [1] 4.440892e-16

c)[3.2, 4]

metodo_biseccion(f_2, 3.2, 4, 10^(-2),100)
## $aprox
## [1] 3.60000 3.40000 3.50000 3.45000 3.42500 3.41250 3.41875
## 
## $precision
## [1] 0.00625
## 
## $iteraciones
## [1] 7
bisect(f_2, 3.2, 4)
## $root
## [1] 3.414214
## 
## $f.root
## [1] -2.131628e-14
## 
## $iter
## [1] 52
## 
## $estim.prec
## [1] 4.440892e-16

Ejercicio 3

Usa el metodo de la bisección para encontrar las soluciones con una precisión de \(10^{-5}\) para los siguientes problemas.

  1. \(x-2^{-x}=0\) para \(0\leq x\leq 1\)
f_3a <- function(x){x-2^(-x)}

x_3a <- seq(from=-3, to=3, by=0.1)
y_3a <- f_3a(x_3a)

graf_3a <- ggplot()+
  geom_vline(xintercept = 0, linetype="dashed")+ #eje x
  geom_hline(yintercept = 0, linetype="dashed")+ #eje y
  geom_line(aes(x=x_3a, y=y_3a), color="blue", size=1)+
  #coord_fixed(ratio = 1)+ # misma escala en los ejes
  labs(x="x", y="f(x)", title="Método de bisección")+
  theme_bw()

#plot(graf_3a)

ggplotly(graf_3a)
metodo_biseccion(f_3a, 0, 1, 10^-5, 100)
## $aprox
##  [1] 0.5000000 0.7500000 0.6250000 0.6875000 0.6562500 0.6406250 0.6484375
##  [8] 0.6445312 0.6425781 0.6416016 0.6411133 0.6413574 0.6412354 0.6411743
## [15] 0.6412048 0.6411896 0.6411819
## 
## $precision
## [1] 7.629395e-06
## 
## $iteraciones
## [1] 17
bisect(f_3a, 0, 1)
## $root
## [1] 0.6411857
## 
## $f.root
## [1] 0
## 
## $iter
## [1] 54
## 
## $estim.prec
## [1] 1.110223e-16
  1. \(e^x-x^2+3x-2=0\) para \(0\leq x\leq 1\)
f_3b <- function(x){exp(x)-x^2+3*x-2}

x_3b <- seq(from=-5, to=5, by=0.1)
y_3b <- f_3b(x_3b)

graf_3b <- ggplot()+
  geom_vline(xintercept = 0, linetype="dashed")+ #eje x
  geom_hline(yintercept = 0, linetype="dashed")+ #eje y
  geom_line(aes(x=x_3b, y=y_3b), color="blue", size=1)+
  #coord_fixed(ratio = 1)+ # misma escala en los ejes
  labs(x="x", y="f(x)", title="Método de bisección")+
  theme_bw()

#plot(graf_3b)

ggplotly(graf_3b)
metodo_biseccion(f_3b, 0, 1, 10^-5, 100)
## $aprox
##  [1] 0.5000000 0.2500000 0.3750000 0.3125000 0.2812500 0.2656250 0.2578125
##  [8] 0.2539062 0.2558594 0.2568359 0.2573242 0.2575684 0.2574463 0.2575073
## [15] 0.2575378 0.2575226 0.2575302
## 
## $precision
## [1] 7.629395e-06
## 
## $iteraciones
## [1] 17
bisect(f_3b, 0, 1)
## $root
## [1] 0.2575303
## 
## $f.root
## [1] -4.440892e-16
## 
## $iter
## [1] 55
## 
## $estim.prec
## [1] 5.551115e-17
  1. \(2x\cos (2x)-(x+1)^2=0\) para \(-3\leq x\leq -2\) y \(-1\leq x \leq 0\)
f_3c <- function(x){2*x*cos(2*x)-(x+1)^2}

x_3c <- seq(from=-3.2, to=2, by=0.01)
y_3c <- f_3c(x_3c)

graf_3c <- ggplot()+
  geom_vline(xintercept = 0, linetype="dashed")+ #eje x
  geom_hline(yintercept = 0, linetype="dashed")+ #eje y
  geom_line(aes(x=x_3c, y=y_3c), color="blue", size=1)+
  #coord_fixed(ratio = 1)+ # misma escala en los ejes
  labs(x="x", y="f(x)", title="Método de bisección")+
  theme_bw()

#plot(graf_3c)

ggplotly(graf_3c)
metodo_biseccion(f_3c, -3, -2, 10^-5, 100)
## $aprox
##  [1] -2.500000 -2.250000 -2.125000 -2.187500 -2.218750 -2.203125 -2.195312
##  [8] -2.191406 -2.189453 -2.190430 -2.190918 -2.191162 -2.191284 -2.191345
## [15] -2.191315 -2.191299 -2.191307
## 
## $precision
## [1] 7.629395e-06
## 
## $iteraciones
## [1] 17
bisect(f_3c, -3, -2)
## $root
## [1] -2.191308
## 
## $f.root
## [1] -3.108624e-15
## 
## $iter
## [1] 52
## 
## $estim.prec
## [1] 4.440892e-16
  1. \(x\cos x-2x^2+3x-1=0\) para \(0.2\leq x\leq 0.3\) y \(1.2\leq x \leq 1.3\)
f_3d <- function(x){x*cos(x)-2*x^2+3*x-1}

x_3d <- seq(from=-4, to=4, by=0.01)
y_3d <- f_3d(x_3d)

graf_3d <- ggplot()+
  geom_vline(xintercept = 0, linetype="dashed")+ #eje x
  geom_hline(yintercept = 0, linetype="dashed")+ #eje y
  geom_line(aes(x=x_3d, y=y_3d), color="blue", size=1)+
  #coord_fixed(ratio = 1)+ # misma escala en los ejes
  labs(x="x", y="f(x)", title="Método de bisección")+
  theme_bw()

#plot(graf_3d)

ggplotly(graf_3d)
metodo_biseccion(f_3d, 1.2, 1.3, 10^-5, 100)
## $aprox
##  [1] 1.250000 1.275000 1.262500 1.256250 1.259375 1.257812 1.257031 1.256641
##  [9] 1.256445 1.256543 1.256592 1.256616 1.256628 1.256622
## 
## $precision
## [1] 6.103516e-06
## 
## $iteraciones
## [1] 14
bisect(f_3d, .2, .3)
## $root
## [1] 0.2975302
## 
## $f.root
## [1] 0
## 
## $iter
## [1] 52
## 
## $estim.prec
## [1] 5.551115e-17

Ejercicio 4

Considera las funciones \(f(x)=x\) y \(g(x)=2 \sin x\). Usa el método de la bisección para encontrar una aproximación con una precisión de \(10^{-5}\) para el primer valor positivo \(x\) tal que \(f(x)=g(x)\).

f_4 <- function(x){x}
g_4 <- function(x){2*sin(x)}
  
x_4 <- seq(from=-8, to=8, by=0.01)
y_f_4 <- f_4(x_4)
y_g_4 <- g_4(x_4)

graf_4 <- ggplot()+
  geom_vline(xintercept = 0, linetype="dashed")+ #eje x
  geom_hline(yintercept = 0, linetype="dashed")+ #eje y
  geom_line(aes(x=x_4, y=y_f_4), color="red", size=0.5)+
  geom_line(aes(x=x_4, y=y_g_4), color="blue", size=0.5)+
  #coord_fixed(ratio = 1)+ # misma escala en los ejes
  labs(x="x", y="f(x)", title="Método de bisección ")+
  theme_bw()

#plot(graf_4)

ggplotly(graf_4)
metodo_biseccion(f_4, -0.2, -0.3, 10^-5, 100)
## $aprox
## [1] -0.25
## 
## $precision
## [1] -0.05
## 
## $iteraciones
## [1] 1
bisect(f_4, -3, 2)
## $root
## [1] 0
## 
## $f.root
## [1] 0
## 
## $iter
## [1] 2
## 
## $estim.prec
## [1] 0

Ejercicio 5

Sea \(f(x)=(x+2)(x+1)x(x-1)^3(x-2)\). ¿A cuál raíz de \(f\) converge el método de la bisección cuando se aplica a los siguientes intervalos?

f_5 <- function(x){(x+2)*(x+1)*x*(x-1)^3*(x-2)}

x_5 <- seq(from=-8, to=8, by=0.01)
y_5 <- f_5(x_5)

graf_5 <- ggplot()+
  geom_vline(xintercept = 0, linetype="dashed")+ #eje x
  geom_hline(yintercept = 0, linetype="dashed")+ #eje y
  geom_line(aes(x=x_5, y=y_5), color="blue", size=1)+
  #coord_fixed(ratio = 1)+ # misma escala en los ejes
  labs(x="x", y="f(x)", title="Método de bisección")+
  theme_bw()

#plot(graf_5)

ggplotly(graf_5)

\[\begin{equation} a) [-3,2.5]\qquad \qquad b) [-2.5, 3]\qquad\qquad c)[-1.75, 1.5]\qquad\qquad d) [-1.5, 1.75] \end{equation}\] a) [-3,2.5]

metodo_biseccion(f_5, -3, 2.5, 10^-6, 100)
## $aprox
##  [1] -0.250000  1.125000  1.812500  2.156250  1.984375  2.070312  2.027344
##  [8]  2.005859  1.995117  2.000488  1.997803  1.999146  1.999817  2.000153
## [15]  1.999985  2.000069  2.000027  2.000006  1.999995  2.000000  1.999998
## [22]  1.999999  2.000000
## 
## $precision
## [1] 6.556511e-07
## 
## $iteraciones
## [1] 23
bisect(f_4, -3, 2.5)
## $root
## [1] 0
## 
## $f.root
## [1] 0
## 
## $iter
## [1] 2
## 
## $estim.prec
## [1] 0
  1. [-2.5, 3]
metodo_biseccion(f_5, -2.5, 3, 10^-5, 100)
## $aprox
##  [1]  0.250000 -1.125000 -1.812500 -2.156250 -1.984375 -2.070312 -2.027344
##  [8] -2.005859 -1.995117 -2.000488 -1.997803 -1.999146 -1.999817 -2.000153
## [15] -1.999985 -2.000069 -2.000027 -2.000006 -1.999995 -2.000000
## 
## $precision
## [1] 5.245209e-06
## 
## $iteraciones
## [1] 20
bisect(f_4, -2.5, 3)
## $root
## [1] 0
## 
## $f.root
## [1] 0
## 
## $iter
## [1] 2
## 
## $estim.prec
## [1] 0

c)[-1.75, 1.5]

metodo_biseccion(f_5, -1.75, 1.5, 10^-5, 100)
## $aprox
##  [1] -0.1250000 -0.9375000 -1.3437500 -1.1406250 -1.0390625 -0.9882812
##  [7] -1.0136719 -1.0009766 -0.9946289 -0.9978027 -0.9993896 -1.0001831
## [13] -0.9997864 -0.9999847 -1.0000839 -1.0000343 -1.0000095 -0.9999971
## [19] -1.0000033
## 
## $precision
## [1] 6.198883e-06
## 
## $iteraciones
## [1] 19
bisect(f_4, -1.75, 1.5)
## $root
## [1] 0
## 
## $f.root
## [1] 0
## 
## $iter
## [1] 2
## 
## $estim.prec
## [1] 0
  1. [-1.5, 1.75]
metodo_biseccion(f_5, -1.5, 1.75, 10^-7, 100)
## $aprox
##  [1] 0.1250000 0.9375000 1.3437500 1.1406250 1.0390625 0.9882812 1.0136719
##  [8] 1.0009766 0.9946289 0.9978027 0.9993896 1.0001831 0.9997864 0.9999847
## [15] 1.0000839 1.0000343 1.0000095 0.9999971 1.0000033 1.0000002 0.9999987
## [22] 0.9999995 0.9999999 1.0000000 0.9999999
## 
## $precision
## [1] 9.685755e-08
## 
## $iteraciones
## [1] 25
bisect(f_4, -1.5, 1.5)
## $root
## [1] 0
## 
## $f.root
## [1] 0
## 
## $iter
## [1] 2
## 
## $estim.prec
## [1] 0

Ejercicio 6

En cada una de las siguientes ecuaciones, determina un intervalo \([a,b]\) en que convergerá la iteración de punto fijo. Estima la cantidad de iteraciones necesarias para obtener aproximaciones con una exactitud de \(10^{-5}\) y realiza los cálculos.

it_pf <- function(g, q0, pr=1e-5, N=100){
  cond <- 1
  it <- 1
  q <- q0
  while(cond==1){
    if(it<=N){
      q[it+1] = g(q[it]) # iteración de la función 
      pr_it <- abs(q[it+1]-q[it]) # precisión en la iteración 
       if(pr_it<pr){
          resultados <- list(sucesion=q, precision=pr_it, iteraciones=it)
          return(resultados)
          cond <- 0
          }#final del segundo if
        else{it <- it+1}
    }#final del primer if
    else{
      print("Se alcanzo el maximo de iteraciones")
      cond <- 0
    }#fin del else
  }#final del while
}# final de la función
  1. \(\quad x=\frac{2-e^{x}+x^{2}}{3}\)
f_6 <- function(x){x}
g_6a<- function(x){(2-exp(x)+x^2)/3}
  
x_6a <- seq(from=-3, to=3 , by=0.01)
y_f_6a <- f_6(x_6a)
y_g_6a <- g_6a(x_6a)

graf_6a <- ggplot()+
  geom_vline(xintercept = 0, linetype="dashed")+ #eje x
  geom_hline(yintercept = 0, linetype="dashed")+ #eje y
  geom_line(aes(x=x_6a, y=y_f_6a), color="gold", size=1)+
  geom_line(aes(x=x_6a, y=y_g_6a), color="forestgreen", size=1)+
  coord_fixed(ratio = 1)+ #misma escala en los ejes
  labs(x="x", y="f(x)", title="Punto fijo gráfica 6a ")+
  theme_bw()

#plot(graf_6a)

ggplotly(graf_6a)
  1. \(\quad x=\frac{5}{x^{2}}+2\)
f_6b<- function(x){x}
g_6b<- function(x){(5/(x^2))+2}
  
x_6b <- seq(from=2, to=3, by=0.01)
y_f_6b <- f_6(x_6b)
y_g_6b <- g_6b(x_6b)

graf_6b <- ggplot()+
  #geom_vline(xintercept = 0, linetype="dashed")+ #eje x
  #geom_hline(yintercept = 0, linetype="dashed")+ #eje y
  geom_line(aes(x=x_6b, y=y_f_6b), color="red", size=0.5)+
  geom_line(aes(x=x_6b, y=y_g_6b), color="green", size=0.5)+
  geom_polygon(aes(x=c(2.9,2.4,2.4,2.9), y=c (3, 3, 2.4, 2.4)),   size=0.5, color= "blue", fill=NA)+
  coord_fixed(ratio=1)+
  labs(x="x", y="f(x)", title="Punto fijo  ejercicio 6b")+
  theme_bw()

#plot(graf_6b)

ggplotly(graf_6b)
  1. \(\quad x=\left(e^{x} / 3\right)^{1 / 2}\)
f_6<- function(x){x}
g_6c<- function(x){sqrt(exp(x)/3)}
  
x_6c <- seq(from=-2, to=4, by=0.01)
y_f_6c <- f_6(x_6c)
y_g_6c <- g_6c(x_6c)

graf_6c <- ggplot()+
  geom_vline(xintercept = 0, linetype="dashed")+ #eje x
  geom_hline(yintercept = 0, linetype="dashed")+ #eje y
  geom_line(aes(x=x_6c, y=y_f_6c), color="red", size=0.5)+
  geom_line(aes(x=x_6c, y=y_g_6c), color="green", size=0.5)+
  geom_polygon(aes(x=c(0.5,1,1,0.5), y=c (0.5, 0.5, 1, 1)),   size=0.5, color= "blue", fill=NA)+
  coord_fixed(ratio=1)+
  labs(x="x", y="f(x)", title="Punto fijo  ejercicio 6c")+
  theme_bw()

#plot(graf_6c)

ggplotly(graf_6c)
  1. \(\quad x=5^{-x}\)
f_6<- function(x){x}
g_6d<- function(x){5^(-x)}
  
x_6d <- seq(from=-1, to=3, by=0.01)
y_f_6d <- f_6(x_6d)
y_g_6d <- g_6d(x_6d)

graf_6d <- ggplot()+
  geom_vline(xintercept = 0, linetype="dashed")+ #eje x
  geom_hline(yintercept = 0, linetype="dashed")+ #eje y
  geom_line(aes(x=x_6d, y=y_f_6d), color="red", size=0.5)+
  geom_line(aes(x=x_6d, y=y_g_6d), color="green", size=0.5)+
  geom_polygon(aes(x=c(.3, .6, .6, .3), y=c (.3, .3, .6, .6)),   size=0.5, color= "blue", fill=NA)+
  coord_fixed(ratio=1)+
  labs(x="x", y="f(x)", title="Punto fijo  ejercicio 6d")+
  theme_bw()

#plot(graf_6d)

ggplotly(graf_6d)
  1. \(\quad x=6^{-x}\)
f_6<- function(x){x}
g_6e<- function(x){6^(-x)}
  
x_6e <- seq(from=-2, to=4, by=0.01)
y_f_6e <- f_6(x_6e)
y_g_6e <- g_6e(x_6e)

graf_6e <- ggplot()+
  geom_vline(xintercept = 0, linetype="dashed")+ #eje x
  geom_hline(yintercept = 0, linetype="dashed")+ #eje y
  geom_line(aes(x=x_6e, y=y_f_6e), color="red", size=0.5)+
  geom_line(aes(x=x_6e, y=y_g_6e), color="green", size=0.5)+
  geom_polygon(aes(x=c(.3, .6, .3, .6), y=c (.3, .3, .6, .6)),   size=0.5, color= "blue", fill=NA)+
  coord_fixed(ratio=1)+
  labs(x="x", y="f(x)", title="Punto fijo  ejercicio 6e")+
  theme_bw()

#plot(graf_6e)

ggplotly(graf_6e)
  1. \(\quad x=0.5(\sin x+\cos x)\)
f_6<- function(x){x}
g_6f<- function(x){0.5*(sin(x)+cos(x))}
  
x_6f <- seq(from=-4, to=4, by=0.01)
y_f_6f <- f_6(x_6f)
y_g_6f <- g_6f(x_6f)

graf_6f <- ggplot()+
  geom_vline(xintercept = 0, linetype="dashed")+ #eje x
  geom_hline(yintercept = 0, linetype="dashed")+ #eje y
  geom_line(aes(x=x_6f, y=y_f_6f), color="red", size=0.5)+
  geom_line(aes(x=x_6f, y=y_g_6f), color="green", size=0.5)+
  geom_polygon(aes(x=c(0,1,1,0), y=c (0, 0, 1, 1)),   size=0.5, color= "blue", fill=NA)+
  coord_fixed(ratio=1)+
  labs(x="x", y="f(x)", title="Punto fijo  ejercicio 6f")+
  theme_bw()

#plot(graf_6f)

ggplotly(graf_6f)