forked from santiagoroa1/An-lisis-N-merico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tarea #1
54 lines (46 loc) · 980 Bytes
/
Tarea #1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Remueve todos los objetos creados
rm(list=ls())
Fx <- function(x) exp(x) -pi * x
# Halla la raiz de Fx
biseccion <- function(a,b) {
x<-seq(a,b,0.1)
plot(x,Fx(x),type="l",col="blue")
abline(h=0,col="blue")
x <- b
d <- (a+b)/2
i <- 0
error <- abs(a-b)/2
while (error > 1.e-8) {
i <- i+1
if (Fx(x) == 0) break
if (Fx(x)*Fx(a) < 0) b <- x else {a <- x}
d<-x
x<-(a+b)/2
#points(rbind(c(x,0)),pch=17,cex=0.7,col="red")
text(x,0,i,cex=0.8,col="red")
error<-abs(a-b)/2
cat("i = " , i,"\tX= ",x,"\tE=",error,"\n")
}
}
biseccion(1,3)
# Remueve todos los objetos creados
rm(list=ls())
Fx <- function(x) exp(x) - x*pi
Gx <- function(x) exp(x) / pi
puntoFijo <- function(a,b)
{
x<-(a+b)/2
i<-0
while (Gx(x) != x )
{
error<-abs(a-b)/2
if(error > 1.e-8)
if (Gx(x) < x) b <- x
else {a <- x}
else {break}
x<-(a+b)/2
i<-i+1
cat("I=",i,"\tG(x) =",Gx(x),"\tX=",x,"\tE=",error,"\n")
}
}
puntoFijo(-3,1)