mnspy 0.9.16__py3-none-any.whl → 0.9.17__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -88,17 +88,15 @@ class Biseccion(Raices):
88
88
  print("La raíz no está dentro de este rango, pruebe con otro rango de datos")
89
89
  sys.exit()
90
90
 
91
- # Bucle de iteración para evitar recursión profunda
92
- while True:
93
- self.x = (self._x_min + self._x_max) / 2
94
-
95
- if self._fin_iteracion():
96
- break # Convergencia o máximo de iteraciones alcanzado
97
-
98
- if np.sign(self._f(self._x_min)) == np.sign(self._f(self.x)):
99
- self._x_min = self.x
100
- else:
101
- self._x_max = self.x
91
+ self.x = (self._x_min + self._x_max) / 2
92
+ if self._fin_iteracion():
93
+ return
94
+ elif np.sign(self._f(self._x_min)) == np.sign(self._f(self.x)):
95
+ self._x_min = self.x
96
+ self._calcular()
97
+ elif np.sign(self._f(self._x_max)) == np.sign(self._f(self.x)):
98
+ self._x_max = self.x
99
+ self._calcular()
102
100
 
103
101
  def graficar(self, mostrar_sol: bool = True, mostrar_iter: bool = True, mostrar_lin_iter: bool = True,
104
102
  n_puntos: int = 100):
@@ -99,53 +99,48 @@ class Brent(Raices):
99
99
  "signos diferentes")
100
100
  sys.exit()
101
101
 
102
- # Bucle de iteración para evitar recursión profunda
103
- while True:
104
- x_a, x_b, x_c = self._val
105
- y_a, y_b, y_c = self._val_f
106
- x_d = 0 # No se usa en la lógica actual, pero se mantiene por si se reimplementa una condición
107
-
108
- self._x_min = min([x_a, x_b])
109
- self._x_max = max([x_a, x_b])
110
-
111
- if len(self._val_f) == len(set(self._val_f)):
112
- # Si los valores de y son distintos, se usa interpolación cuadrática inversa
113
- self.x = (x_a * y_b * y_c / ((y_a - y_b) * (y_a - y_c)) +
114
- x_b * y_a * y_c / ((y_b - y_a) * (y_b - y_c)) +
115
- x_c * y_a * y_b / ((y_c - y_a) * (y_c - y_b)))
116
- else:
117
- # Si hay valores de y repetidos, se usa el método de la secante (falsa posición)
118
- self.x = (y_a * x_b - y_b * x_a) / (y_a - y_b)
119
-
120
- # Se verifica si el paso de interpolación es aceptable, si no, se usa bisección
121
- cond1 = (self.x - (3 * x_a + x_b) / 4) * (self.x - x_b) >= 0
122
- cond2 = self._biseccion_usada and abs(self.x - x_b) >= abs(x_b - x_c) / 2
123
- cond3 = not self._biseccion_usada and abs(self.x - x_b) >= abs(x_c - x_d) / 2
124
-
125
- if cond1 or cond2 or cond3:
126
- self.x = (x_a + x_b) / 2
127
- self._biseccion_usada = True
128
- else:
129
- self._biseccion_usada = False
130
-
131
- if self._fin_iteracion():
132
- break
133
-
134
- y_x = self._f(self.x)
135
- x_c, y_c = x_b, y_b # Actualizar el punto previo
136
-
137
- if np.sign(y_a) == np.sign(y_x):
138
- x_a, y_a = self.x, y_x
139
- else:
140
- x_b, y_b = self.x, y_x
141
-
142
- # Se asegura de nuevo que |f(a)| > |f(b)| para la siguiente iteración
143
- if abs(y_a) < abs(y_b):
144
- x_a, x_b = x_b, x_a
145
- y_a, y_b = y_b, y_a
146
-
147
- self._val = x_a, x_b, x_c
148
- self._val_f = y_a, y_b, y_c
102
+ x_a, x_b, x_c = self._val
103
+ y_a, y_b, y_c = self._val_f
104
+ x_d = 0
105
+ self._x_min = min([x_a, x_b])
106
+ self._x_max = max([x_a, x_b])
107
+ if len(self._val_f) == len(set(self._val_f)):
108
+ # si los y son diferentes se usa el método de la cuadrática inversa
109
+ self.x = x_a * y_b * y_c / ((y_a - y_b) * (y_a - y_c)) + x_b * y_a * y_c / (
110
+ (y_b - y_a) * (y_b - y_c)) + x_c * y_a * y_b / ((y_c - y_a) * (y_c - y_b))
111
+ else:
112
+ # Se usa el método de la falsa posición
113
+ self.x = (y_a * x_b - y_b * x_a) / (y_a - y_b)
114
+ if (self.x - (3 * x_a + x_b) / 4) * (self.x - x_b) >= 0 or (
115
+ self._biseccion_usada and abs(self.x - x_b) >= abs(x_b - x_c) / 2) or (
116
+ not self._biseccion_usada and abs(self.x - x_b) >= abs(x_c - x_d) / 2):
117
+ self.x = (x_a + x_b) / 2
118
+ self._biseccion_usada = True
119
+ else:
120
+ self._biseccion_usada = False
121
+ y_x = self._f(self.x)
122
+ # x_d = x_c # TODO Revisar el código esta variable porque no se usa
123
+ x_c = x_b
124
+ y_c = y_b
125
+ if np.sign(y_a) == np.sign(y_x):
126
+ x_a = self.x
127
+ y_a = y_x
128
+ else:
129
+ x_b = self.x
130
+ y_b = y_x
131
+ if abs(y_a) < abs(y_b):
132
+ x_t = x_a
133
+ y_t = y_a
134
+ x_a = x_b
135
+ y_a = y_b
136
+ x_b = x_t
137
+ y_b = y_t
138
+ self._val = x_a, x_b, x_c
139
+ self._val_f = y_a, y_b, y_c
140
+ if self._fin_iteracion():
141
+ return
142
+ else:
143
+ self._calcular()
149
144
 
150
145
  def graficar(self, mostrar_sol: bool = True, mostrar_iter: bool = True, mostrar_lin_iter: bool = False,
151
146
  n_puntos: int = 100):
@@ -86,18 +86,16 @@ class FalsaPosicion(Raices):
86
86
  print("La raíz no está dentro de este rango, pruebe con otro rango de datos")
87
87
  sys.exit()
88
88
 
89
- # Bucle de iteración para evitar recursión profunda
90
- while True:
91
- self.x = self._x_max - (self._f(self._x_max) * (self._x_min - self._x_max)) / (
92
- self._f(self._x_min) - self._f(self._x_max))
93
-
94
- if self._fin_iteracion():
95
- break # Convergencia o máximo de iteraciones alcanzado
96
-
97
- if np.sign(self._f(self._x_min)) == np.sign(self._f(self.x)):
98
- self._x_min = self.x
99
- else:
100
- self._x_max = self.x
89
+ self.x = self._x_max - (self._f(self._x_max) * (self._x_min - self._x_max)) / (
90
+ self._f(self._x_min) - self._f(self._x_max))
91
+ if self._fin_iteracion():
92
+ return
93
+ elif np.sign(self._f(self._x_min)) == np.sign(self._f(self.x)):
94
+ self._x_min = self.x
95
+ self._calcular()
96
+ elif np.sign(self._f(self._x_max)) == np.sign(self._f(self.x)):
97
+ self._x_max = self.x
98
+ self._calcular()
101
99
 
102
100
  def graficar(self, mostrar_sol: bool = True, mostrar_iter: bool = True, mostrar_lin_iter: bool = True,
103
101
  n_puntos: int = 100):
@@ -88,40 +88,34 @@ class Muller(Raices):
88
88
  -------
89
89
  None
90
90
  """
91
- # Bucle de iteración para evitar recursión profunda
92
- while True:
93
- h_0 = self._x_1_i - self._x_0_i
94
- h_1 = self._x_2_i - self._x_1_i
95
- d_0 = (self._f(self._x_1_i) - self._f(self._x_0_i)) / h_0
96
- d_1 = (self._f(self._x_2_i) - self._f(self._x_1_i)) / h_1
97
-
98
- # Coeficientes de la parábola a*x^2 + b*x + c
99
- a = (d_1 - d_0) / (h_1 + h_0)
100
- b = a * h_1 + d_1
101
- c = self._f(self._x_2_i)
102
-
103
- # Guardar coeficientes para graficar
104
- self._a_2.append(a)
105
- self._a_1.append(d_0)
106
- self._a_0.append(self._f(self._x_0_i))
107
- self._list_x_0.append(self._x_0_i)
108
- self._list_x_1.append(self._x_1_i)
109
- self._list_x_2.append(self._x_2_i)
110
-
111
- # Fórmula cuadrática, se elige el denominador más grande para evitar restas catastróficas.
112
- rad = np.sqrt(b ** 2 - 4 * a * c)
113
- if abs(b + rad) > abs(b - rad):
114
- den = b + rad
115
- else:
116
- den = b - rad
117
-
118
- self.x = self._x_2_i - (2 * c / den)
119
-
120
- if self._fin_iteracion():
121
- break # Convergencia o máximo de iteraciones alcanzado
122
-
123
- # Actualizar los puntos para la siguiente iteración
124
- self._x_0_i, self._x_1_i, self._x_2_i = self._x_1_i, self._x_2_i, self.x
91
+ h_0 = self._x_1_i - self._x_0_i
92
+ h_1 = self._x_2_i - self._x_1_i
93
+ d_0 = (self._f(self._x_1_i) - self._f(self._x_0_i)) / h_0
94
+ d_1 = (self._f(self._x_2_i) - self._f(self._x_1_i)) / h_1
95
+ a = (d_1 - d_0) / (h_1 + h_0)
96
+ b = a * h_1 + d_1
97
+ c = self._f(self._x_2_i)
98
+ # ***
99
+ self._a_2 += [a]
100
+ self._a_1 += [d_0]
101
+ self._a_0 += [self._f(self._x_0_i)]
102
+ self._list_x_0 += [self._x_0_i]
103
+ self._list_x_1 += [self._x_1_i]
104
+ self._list_x_2 += [self._x_2_i]
105
+ # ***
106
+ rad = np.sqrt(b ** 2 - 4 * a * c)
107
+ if abs(b + rad) > abs(b - rad):
108
+ den = b + rad
109
+ else:
110
+ den = b - rad
111
+ self.x = self._x_2_i - 2 * c / den
112
+ if self._fin_iteracion():
113
+ return
114
+ else:
115
+ self._x_0_i = self._x_1_i
116
+ self._x_1_i = self._x_2_i
117
+ self._x_2_i = self.x
118
+ self._calcular()
125
119
 
126
120
  def graficar(self, mostrar_sol: bool = True, mostrar_iter: bool = True, mostrar_lin_iter: bool = True,
127
121
  n_puntos: int = 100):
@@ -117,9 +117,11 @@ class NewtonRaphson(Raices):
117
117
  -------
118
118
  None
119
119
  """
120
- # Bucle de iteración para evitar recursión profunda
121
- while not self._fin_iteracion():
122
- self.x -= self._f(self.x) / self._df(self.x)
120
+ self.x -= self._f(self.x) / self._df(self.x)
121
+ if self._fin_iteracion():
122
+ return
123
+ else:
124
+ self._calcular()
123
125
 
124
126
  def graficar(self, mostrar_sol: bool = True, mostrar_iter: bool = True, mostrar_lin_iter: bool = True,
125
127
  n_puntos: int = 100):
@@ -74,10 +74,11 @@ class PuntoFijo(Raices):
74
74
  -------
75
75
  None
76
76
  """
77
- # Bucle de iteración para evitar recursión profunda
78
- while not self._fin_iteracion():
79
- # self.x = self._f(self.x) # La función f es en realidad g(x)
80
- self.x = self._f(self.x)
77
+ self.x += self._f(self.x) - self.x
78
+ if self._fin_iteracion():
79
+ return
80
+ else:
81
+ self._calcular()
81
82
 
82
83
  def graficar(self, mostrar_sol: bool = True, mostrar_iter: bool = True, mostrar_lin_iter: bool = True,
83
84
  n_puntos: int = 100):
@@ -82,7 +82,7 @@ class Raices:
82
82
  Tipo de error a utilizar para la convergencia:
83
83
  - ``'%'``: Error relativo porcentual (por defecto).
84
84
  - ``'/'``: Error relativo.
85
- - ``'n'``: Número de cifras significativas.
85
+ - ``'n'``: Número de cifras significativas. εs = (0.5 * 10^(2-n)) % (Scarborough, 1966)
86
86
  """
87
87
  self._f = f
88
88
  self._tol = tol
@@ -80,13 +80,14 @@ class Secante(Raices):
80
80
  -------
81
81
  None
82
82
  """
83
- # Bucle de iteración para evitar recursión profunda
84
- while not self._fin_iteracion():
85
- # Fórmula del método de la secante
86
- self.x = self._x_1_i - (self._f(self._x_1_i) * (self._x_1_i - self._x_0_i)) / (
87
- self._f(self._x_1_i) - self._f(self._x_0_i))
88
- # Actualizar los puntos para la siguiente iteración
89
- self._x_0_i, self._x_1_i = self._x_1_i, self.x
83
+ self.x -= (self._f(self._x_1_i) * (self._x_1_i - self._x_0_i)) / (
84
+ self._f(self._x_1_i) - self._f(self._x_0_i))
85
+ self._x_0_i = self._x_1_i
86
+ self._x_1_i = self.x
87
+ if self._fin_iteracion():
88
+ return
89
+ else:
90
+ self._calcular()
90
91
 
91
92
  def graficar(self, mostrar_sol: bool = True, mostrar_iter: bool = True, mostrar_lin_iter: bool = True,
92
93
  n_puntos: int = 100):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mnspy
3
- Version: 0.9.16
3
+ Version: 0.9.17
4
4
  Summary: Paquete didáctico para métodos numéricos
5
5
  Home-page: https://github.com/EdwinSoft/mnspy
6
6
  Author: Edwin Córdoba
@@ -53,18 +53,18 @@ mnspy/interpolación/inter_spline_cubica.py,sha256=1oBT-t5zVB5RrLx6BkUWweKdwVwI_
53
53
  mnspy/interpolación/inter_spline_lineal.py,sha256=-UZUBcTLKIZqZw2ZZd2qIyxJK2Q4dqlZxRBdz-0jvuY,5196
54
54
  mnspy/interpolación/interpolacion.py,sha256=gV7OoLzGbN-p1L3vr-cXhoYd13vysVpLXpg8JujwfAc,1695
55
55
  mnspy/raíces/__init__.py,sha256=8_8u3bPEoHjh804bNVZVbNM2UOv-RiC7TmzCrz6zHCc,1497
56
- mnspy/raíces/bisección.py,sha256=PHXWJfZ5CZ2jZLlpTdZWjsOI6U_W6MH-HfQwAWZJ5yA,5682
57
- mnspy/raíces/brent.py,sha256=OisCG3poUL5m3XOPip6nARu50UTTSWzOr2JN_Qj8srU,7090
58
- mnspy/raíces/falsa_posicion.py,sha256=XMHdOr_VD4avticGWxFBr2GzVL0y-Qb0hHf7OAI_hwQ,5419
59
- mnspy/raíces/muller.py,sha256=xA77ltemBu-m7HFumazqPFbSpEBmffzfsZKZqzjclC0,6313
60
- mnspy/raíces/newton_raphson.py,sha256=S7DTVCxSwMr1l9YScM7B3dlemN1NIdJM74AaGJApChw,6442
61
- mnspy/raíces/punto_fijo.py,sha256=yGlx3PZ19s2ENtb515ytH1Vxw0Van_6-hyC2XRWLi4g,4711
62
- mnspy/raíces/raices.py,sha256=lTjSOk84sg1VdlElmHaZSRen00zpt0jNrnFBx_SStnU,17510
63
- mnspy/raíces/secante.py,sha256=t8-NcN-Ki8BYrh3Cf3VUjaaRLxz6qV1v5i8johKBlZs,5220
56
+ mnspy/raíces/bisección.py,sha256=JHP8o48I58NWNAQwEDUfzotMTJsY4ZkyHaET_fd1AlE,5638
57
+ mnspy/raíces/brent.py,sha256=RwGSRcAeFp-Qy8XMmcEU6UqEcNb0RP1UYdmVMMiXngs,6689
58
+ mnspy/raíces/falsa_posicion.py,sha256=NAqgo9_U1XkWtUc9s9lcV4IpJ_-vxw_3b5p9pzDOQvs,5371
59
+ mnspy/raíces/muller.py,sha256=XkXLk99TrW_0hYam5CrzrmSJi6fJx-KhhaRL7_xLzcs,5886
60
+ mnspy/raíces/newton_raphson.py,sha256=HccOD0TZovQEzBi16Rcsg7gc7tvlrWPNplcpGDL6g04,6431
61
+ mnspy/raíces/punto_fijo.py,sha256=XCRl-rUsuMkYy2baptXT_wPXBLGht-r2_qegAKwv8xo,4635
62
+ mnspy/raíces/raices.py,sha256=GF6QTry--5piS5F2kw0gSnElNEBajdez-tZB8gQOkZM,17556
63
+ mnspy/raíces/secante.py,sha256=mLYNV4dwy2BLveAlehSVdqiAlY0-ORT-tEDlWbjvs3Y,5082
64
64
  mnspy/raíces/secante_modificada.py,sha256=0bLgcG8K_O6Ras3vKBIQpUdDlB69tWKHbx_fE8-47SE,5105
65
65
  mnspy/raíces/wegstein.py,sha256=23HQ6QuelMNo8S8W1fzha8ozbcy_NdsjK5XLMaH-m38,5397
66
- mnspy-0.9.16.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
67
- mnspy-0.9.16.dist-info/METADATA,sha256=HHpKYobl4Z5NXZj2Or0JDvX9o0m5x4CV9njoPk_LcC4,4641
68
- mnspy-0.9.16.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
69
- mnspy-0.9.16.dist-info/top_level.txt,sha256=fbooZdZwS41I8vFuAXnn5qL4_mfc1aPt_DM60ZpvtKE,6
70
- mnspy-0.9.16.dist-info/RECORD,,
66
+ mnspy-0.9.17.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
67
+ mnspy-0.9.17.dist-info/METADATA,sha256=twCh69elQkudvd9rk65dmONJMOyh3pPgVVJRFAjE0tY,4641
68
+ mnspy-0.9.17.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
69
+ mnspy-0.9.17.dist-info/top_level.txt,sha256=fbooZdZwS41I8vFuAXnn5qL4_mfc1aPt_DM60ZpvtKE,6
70
+ mnspy-0.9.17.dist-info/RECORD,,
File without changes