numanpy 0.0.2__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.0.2 → numanpy-0.1.1}/PKG-INFO +2 -2
- numanpy-0.1.1/numanpy/__init__.py +0 -0
- numanpy-0.1.1/numanpy/root_finding.py +90 -0
- {numanpy-0.0.2 → numanpy-0.1.1}/numanpy.egg-info/PKG-INFO +2 -2
- {numanpy-0.0.2 → numanpy-0.1.1}/numanpy.egg-info/SOURCES.txt +2 -1
- numanpy-0.1.1/numanpy.egg-info/top_level.txt +1 -0
- {numanpy-0.0.2 → numanpy-0.1.1}/pyproject.toml +5 -2
- numanpy-0.0.2/numanpy.egg-info/top_level.txt +0 -1
- {numanpy-0.0.2 → numanpy-0.1.1}/LICENSE +0 -0
- {numanpy-0.0.2 → numanpy-0.1.1}/README.md +0 -0
- {numanpy-0.0.2 → numanpy-0.1.1}/numanpy.egg-info/dependency_links.txt +0 -0
- {numanpy-0.0.2 → 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.
|
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
|
File without changes
|
@@ -0,0 +1,90 @@
|
|
1
|
+
def bisect(f, a, b, eps=1e-6, N=100, verbose=False):
|
2
|
+
"""
|
3
|
+
Bisection method for finding a root of the scalar function f in the interval [a, b].
|
4
|
+
|
5
|
+
Parameters:
|
6
|
+
f (callable): The scalar function for which to find the root.
|
7
|
+
a (float): The start of the interval.
|
8
|
+
b (float): The end of the interval.
|
9
|
+
eps (float): The tolerance for convergence.
|
10
|
+
N (int): The maximum number of iterations.
|
11
|
+
verbose (bool): If True, returns iterates and prints convergence information; else, returns only the root.
|
12
|
+
|
13
|
+
Returns:
|
14
|
+
float: The approximate root of the scalar function f.
|
15
|
+
"""
|
16
|
+
if f(a) * f(b) >= 0:
|
17
|
+
raise ValueError("f(a) and f(b) must have different signs.")
|
18
|
+
cs = []
|
19
|
+
|
20
|
+
for _ in range(N):
|
21
|
+
cs.append((a + b) / 2)
|
22
|
+
c = cs[-1]
|
23
|
+
if abs(f(c)) < eps or (b - a) / 2 < eps:
|
24
|
+
if verbose:
|
25
|
+
print(f"Converged to {c} after {_ + 1} iterations.")
|
26
|
+
return cs
|
27
|
+
else:
|
28
|
+
return c
|
29
|
+
if f(c) * f(a) < 0:
|
30
|
+
b = c
|
31
|
+
else:
|
32
|
+
a = c
|
33
|
+
|
34
|
+
raise RuntimeError("Maximum number of iterations reached without convergence.")
|
35
|
+
|
36
|
+
|
37
|
+
def iterate(f, x0, eps=1e-6, N=100):
|
38
|
+
"""
|
39
|
+
Fixed-point iteration method for finding a root of the scalar function f.
|
40
|
+
|
41
|
+
Parameters:
|
42
|
+
f (callable): The scalar function for which to find the root.
|
43
|
+
x0 (float or ndarray): The initial guess for the root.
|
44
|
+
eps (float): The tolerance for convergence.
|
45
|
+
N (int): The maximum number of iterations.
|
46
|
+
|
47
|
+
Returns:
|
48
|
+
float: The approximate root of the scalar function f.
|
49
|
+
"""
|
50
|
+
x = x0
|
51
|
+
for _ in range(N):
|
52
|
+
x_ = f(x)
|
53
|
+
if abs(x_ - x) < eps:
|
54
|
+
return x_
|
55
|
+
x = x_
|
56
|
+
|
57
|
+
raise RuntimeError("Maximum number of iterations reached without convergence.")
|
58
|
+
|
59
|
+
|
60
|
+
def newton(f, df, x0, eps=1e-6, N=100, verbose=False):
|
61
|
+
"""
|
62
|
+
Newton's method for finding a root of the scalar function f.
|
63
|
+
|
64
|
+
Parameters:
|
65
|
+
f (callable): The scalar function for which to find the root.
|
66
|
+
df (callable): The derivative of the scalar function f.
|
67
|
+
x0 (float or ndarray): The initial guess for the root.
|
68
|
+
eps (float): The tolerance for convergence.
|
69
|
+
N (int): The maximum number of iterations.
|
70
|
+
verbose (bool): If True, returns iterates and prints convergence information; else, returns only the root.
|
71
|
+
|
72
|
+
Returns:
|
73
|
+
float: The approximate root of the scalar function f.
|
74
|
+
"""
|
75
|
+
x = [x0]
|
76
|
+
for _ in range(N):
|
77
|
+
fx = f(x[-1])
|
78
|
+
dfx = df(x[-1])
|
79
|
+
if dfx == 0:
|
80
|
+
raise ValueError("Derivative is zero. No solution found.")
|
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]
|
89
|
+
|
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.
|
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
|
@@ -0,0 +1 @@
|
|
1
|
+
numanpy
|
@@ -1,10 +1,10 @@
|
|
1
1
|
[project]
|
2
2
|
name = "numanpy"
|
3
|
-
version = "0.
|
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 = [
|
@@ -27,6 +27,9 @@ classifiers = [
|
|
27
27
|
license = "MIT"
|
28
28
|
license-files = ["LICEN[CS]E*"]
|
29
29
|
|
30
|
+
[tool.setuptools]
|
31
|
+
packages = ["numanpy"] # List all top-level packages
|
32
|
+
|
30
33
|
[project.urls]
|
31
34
|
Homepage = "https://github.com/siddharthskulkarni/numanpy"
|
32
35
|
Issues = "https://github.com/siddharthskulkarni/numanpy/issues"
|
@@ -1 +0,0 @@
|
|
1
|
-
Markov
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|