numanpy 0.1.0__tar.gz → 0.1.1__tar.gz
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.
- {numanpy-0.1.0 → numanpy-0.1.1}/PKG-INFO +2 -2
- {numanpy-0.1.0 → numanpy-0.1.1}/numanpy/root_finding.py +25 -12
- {numanpy-0.1.0 → numanpy-0.1.1}/numanpy.egg-info/PKG-INFO +2 -2
- {numanpy-0.1.0 → numanpy-0.1.1}/pyproject.toml +2 -2
- {numanpy-0.1.0 → numanpy-0.1.1}/LICENSE +0 -0
- {numanpy-0.1.0 → numanpy-0.1.1}/README.md +0 -0
- {numanpy-0.1.0 → numanpy-0.1.1}/numanpy/__init__.py +0 -0
- {numanpy-0.1.0 → numanpy-0.1.1}/numanpy.egg-info/SOURCES.txt +0 -0
- {numanpy-0.1.0 → numanpy-0.1.1}/numanpy.egg-info/dependency_links.txt +0 -0
- {numanpy-0.1.0 → numanpy-0.1.1}/numanpy.egg-info/top_level.txt +0 -0
- {numanpy-0.1.0 → numanpy-0.1.1}/setup.cfg +0 -0
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: numanpy
|
3
|
-
Version: 0.1.
|
4
|
-
Summary: Python library implementing numerical and simulation methods
|
3
|
+
Version: 0.1.1
|
4
|
+
Summary: Python library implementing numerical and simulation methods.
|
5
5
|
Author: Siddharth Kulkarni
|
6
6
|
License-Expression: MIT
|
7
7
|
Project-URL: Homepage, https://github.com/siddharthskulkarni/numanpy
|
@@ -1,4 +1,4 @@
|
|
1
|
-
def bisect(f, a, b, eps=1e-
|
1
|
+
def bisect(f, a, b, eps=1e-6, N=100, verbose=False):
|
2
2
|
"""
|
3
3
|
Bisection method for finding a root of the scalar function f in the interval [a, b].
|
4
4
|
|
@@ -8,17 +8,24 @@ def bisect(f, a, b, eps=1e-5, N=100):
|
|
8
8
|
b (float): The end of the interval.
|
9
9
|
eps (float): The tolerance for convergence.
|
10
10
|
N (int): The maximum number of iterations.
|
11
|
+
verbose (bool): If True, returns iterates and prints convergence information; else, returns only the root.
|
11
12
|
|
12
13
|
Returns:
|
13
14
|
float: The approximate root of the scalar function f.
|
14
15
|
"""
|
15
16
|
if f(a) * f(b) >= 0:
|
16
17
|
raise ValueError("f(a) and f(b) must have different signs.")
|
18
|
+
cs = []
|
17
19
|
|
18
20
|
for _ in range(N):
|
19
|
-
|
21
|
+
cs.append((a + b) / 2)
|
22
|
+
c = cs[-1]
|
20
23
|
if abs(f(c)) < eps or (b - a) / 2 < eps:
|
21
|
-
|
24
|
+
if verbose:
|
25
|
+
print(f"Converged to {c} after {_ + 1} iterations.")
|
26
|
+
return cs
|
27
|
+
else:
|
28
|
+
return c
|
22
29
|
if f(c) * f(a) < 0:
|
23
30
|
b = c
|
24
31
|
else:
|
@@ -27,7 +34,7 @@ def bisect(f, a, b, eps=1e-5, N=100):
|
|
27
34
|
raise RuntimeError("Maximum number of iterations reached without convergence.")
|
28
35
|
|
29
36
|
|
30
|
-
def iterate(f, x0, eps=1e-
|
37
|
+
def iterate(f, x0, eps=1e-6, N=100):
|
31
38
|
"""
|
32
39
|
Fixed-point iteration method for finding a root of the scalar function f.
|
33
40
|
|
@@ -49,7 +56,8 @@ def iterate(f, x0, eps=1e-5, N=100):
|
|
49
56
|
|
50
57
|
raise RuntimeError("Maximum number of iterations reached without convergence.")
|
51
58
|
|
52
|
-
|
59
|
+
|
60
|
+
def newton(f, df, x0, eps=1e-6, N=100, verbose=False):
|
53
61
|
"""
|
54
62
|
Newton's method for finding a root of the scalar function f.
|
55
63
|
|
@@ -59,19 +67,24 @@ def newton(f, df, x0, eps=1e-5, N=100):
|
|
59
67
|
x0 (float or ndarray): The initial guess for the root.
|
60
68
|
eps (float): The tolerance for convergence.
|
61
69
|
N (int): The maximum number of iterations.
|
70
|
+
verbose (bool): If True, returns iterates and prints convergence information; else, returns only the root.
|
62
71
|
|
63
72
|
Returns:
|
64
73
|
float: The approximate root of the scalar function f.
|
65
74
|
"""
|
66
|
-
x = x0
|
75
|
+
x = [x0]
|
67
76
|
for _ in range(N):
|
68
|
-
fx = f(x)
|
69
|
-
dfx = df(x)
|
77
|
+
fx = f(x[-1])
|
78
|
+
dfx = df(x[-1])
|
70
79
|
if dfx == 0:
|
71
80
|
raise ValueError("Derivative is zero. No solution found.")
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
81
|
+
|
82
|
+
x.append(x[-1] - fx / dfx)
|
83
|
+
if abs(x[-1] - x[-2]) < eps:
|
84
|
+
if verbose:
|
85
|
+
print(f"Converged to {x[-1]} after {_ + 1} iterations.")
|
86
|
+
return x
|
87
|
+
else:
|
88
|
+
return x[-1]
|
76
89
|
|
77
90
|
raise RuntimeError("Maximum number of iterations reached without convergence.")
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: numanpy
|
3
|
-
Version: 0.1.
|
4
|
-
Summary: Python library implementing numerical and simulation methods
|
3
|
+
Version: 0.1.1
|
4
|
+
Summary: Python library implementing numerical and simulation methods.
|
5
5
|
Author: Siddharth Kulkarni
|
6
6
|
License-Expression: MIT
|
7
7
|
Project-URL: Homepage, https://github.com/siddharthskulkarni/numanpy
|
@@ -1,10 +1,10 @@
|
|
1
1
|
[project]
|
2
2
|
name = "numanpy"
|
3
|
-
version = "0.1.
|
3
|
+
version = "0.1.1"
|
4
4
|
authors = [
|
5
5
|
{ name="Siddharth Kulkarni" },
|
6
6
|
]
|
7
|
-
description = "Python library implementing numerical and simulation methods"
|
7
|
+
description = "Python library implementing numerical and simulation methods."
|
8
8
|
readme = "README.md"
|
9
9
|
requires-python = ">=3.9"
|
10
10
|
classifiers = [
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|