File - D\GISpython\Aprox_pipy
29
30
31
32
33
34
35
36
37
38
import ni
import matplotlib.pyplot as plt
import math
def Graficos(n):
#PROC
plt. figure ()
#plt.hold(True) -->
Pi_Basilea(n)
plt.plot (m{:,0], m{z,1],
color="red", marker:
"Basilea")
m = Pi_Euler(n) # Aproximacién de PI por Euler
plt.plot(m{:,0], m[:,1], linewidth=1, linestyle=
color="blue", marker="None", label="Euler")
m = Pi_Leibniz(n) # Aprox PI por
plt.plot(m{:,0], m[:,1], linewidth=1, linestyle=
color="black", marker="None", label="Leibniz")
Pi_Viete(n) #
m
rad >
plt.plot(m[:, 0],
color="green", marker:
m= Pi_Wallisin) #
plt.plot(m[:, 0], m
color="c", marker="Non
plt. legend (loc=4)
plt.xlabel ("Namero de Iteracion")
plt.ylabel ("Valor de PI")
plt.title("Aproximacién de PI por Distintos Métodos")
plt.axis ("tight")
plt.grid (True)
plt.show()
1), linewidt:
", label="Wallis:
, linestyle="-",
Page 1 of3File - D\GISpython\Aprox_pipy
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
7
12
13
74
78
16
7
78
79
80
def
en
def
Pi_Basilea(n
# DESCRIPCION: Problema de Basilea, resuelto por Euler
1735
BO ees
np.zeros([n,2])
for i in range(1, n + 1, 1}t
s=s +1 / math.pow(i, 2)
m{i-1,0] =i
m{i-1,1] = math.sqrt(6 * s)
return m
Pi_Euler(n):
# DESCRIPCIO!
APROXIMA El, VALOR DE pi TANTE LA
RELACION DE Euler
def
# DATOS
RESULTADOS:
PROCEDIM
0
np. zeros ([n,2])
for i in range(1, n + 1, 1):
s=s+1/ math.pow(i, 4)
m(i-1,0] = 4
m[i-1,1] = math.pow(90*s, 0.25)
return m
m[j,pi]
#
#
s
m
Pi_Leibniz(n}
# DESCRIPCION:
s=0
m = np.zeros({n,2])
for i in range(n):
s = s + math.pow(-1,i)/(2*i+1)
m[i, 0} = i+1
m[i,1] = 4s
return m
Pi_Viete(n):
# Aproxima Pi mediante el producto r.
&
a
>
a
8
&
Page 2 0f3File - D\GISpython\Aprox_pipy
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105 Graficos (50)
106
107
def Pi_Wallis(n
de Viete, 1593
a math. sqrt (1/2)
b 1
m = np.zeros({n,2])
for i in range(n):
b = bra
a = math. sqrt (1/2+1/2*a)
m(i,O] = itl
mli,l] = 2/b
return m
P
m = np.zeros({n,2])
for i in range(n):
mac = 2*(it1)-1
a nac*(nac + 2)/math.pow(nact1,2)
P = p*a
m[i,0] = i#1
mli,l] = 2/p
return m
LA
Page 303