nummeth 0.1.0__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.
- nummeth-0.1.0/LICENSE +21 -0
- nummeth-0.1.0/PKG-INFO +145 -0
- nummeth-0.1.0/README.md +109 -0
- nummeth-0.1.0/pyproject.toml +58 -0
- nummeth-0.1.0/setup.cfg +4 -0
- nummeth-0.1.0/src/nummeth/__init__.py +132 -0
- nummeth-0.1.0/src/nummeth/applications/__init__.py +4 -0
- nummeth-0.1.0/src/nummeth/applications/circuit.py +78 -0
- nummeth-0.1.0/src/nummeth/calculus/__init__.py +26 -0
- nummeth-0.1.0/src/nummeth/calculus/differentiation.py +21 -0
- nummeth-0.1.0/src/nummeth/calculus/integration.py +178 -0
- nummeth-0.1.0/src/nummeth/core/__init__.py +4 -0
- nummeth-0.1.0/src/nummeth/core/results.py +107 -0
- nummeth-0.1.0/src/nummeth/fitting/__init__.py +4 -0
- nummeth-0.1.0/src/nummeth/fitting/regression.py +123 -0
- nummeth-0.1.0/src/nummeth/interpolation/__init__.py +21 -0
- nummeth-0.1.0/src/nummeth/interpolation/divided_diff.py +88 -0
- nummeth-0.1.0/src/nummeth/interpolation/finite_diff.py +180 -0
- nummeth-0.1.0/src/nummeth/interpolation/lagrange.py +72 -0
- nummeth-0.1.0/src/nummeth/interpolation/spline.py +134 -0
- nummeth-0.1.0/src/nummeth/linear_systems/__init__.py +13 -0
- nummeth-0.1.0/src/nummeth/linear_systems/eigen.py +82 -0
- nummeth-0.1.0/src/nummeth/linear_systems/elimination.py +92 -0
- nummeth-0.1.0/src/nummeth/linear_systems/iterative.py +127 -0
- nummeth-0.1.0/src/nummeth/linear_systems/matrix_ops.py +65 -0
- nummeth-0.1.0/src/nummeth/ode/__init__.py +12 -0
- nummeth-0.1.0/src/nummeth/ode/euler.py +103 -0
- nummeth-0.1.0/src/nummeth/ode/predictor_corrector.py +64 -0
- nummeth-0.1.0/src/nummeth/ode/runge_kutta.py +113 -0
- nummeth-0.1.0/src/nummeth/pde/__init__.py +12 -0
- nummeth-0.1.0/src/nummeth/pde/elliptic.py +135 -0
- nummeth-0.1.0/src/nummeth/pde/hyperbolic.py +92 -0
- nummeth-0.1.0/src/nummeth/pde/parabolic.py +148 -0
- nummeth-0.1.0/src/nummeth/roots/__init__.py +14 -0
- nummeth-0.1.0/src/nummeth/roots/bisection.py +86 -0
- nummeth-0.1.0/src/nummeth/roots/false_position.py +73 -0
- nummeth-0.1.0/src/nummeth/roots/fixed_point.py +55 -0
- nummeth-0.1.0/src/nummeth/roots/newton_raphson.py +66 -0
- nummeth-0.1.0/src/nummeth/roots/secant.py +63 -0
- nummeth-0.1.0/src/nummeth.egg-info/PKG-INFO +145 -0
- nummeth-0.1.0/src/nummeth.egg-info/SOURCES.txt +49 -0
- nummeth-0.1.0/src/nummeth.egg-info/dependency_links.txt +1 -0
- nummeth-0.1.0/src/nummeth.egg-info/requires.txt +16 -0
- nummeth-0.1.0/src/nummeth.egg-info/top_level.txt +1 -0
- nummeth-0.1.0/tests/test_calculus.py +29 -0
- nummeth-0.1.0/tests/test_fitting.py +21 -0
- nummeth-0.1.0/tests/test_interpolation.py +28 -0
- nummeth-0.1.0/tests/test_linear_systems.py +45 -0
- nummeth-0.1.0/tests/test_ode.py +24 -0
- nummeth-0.1.0/tests/test_pde.py +43 -0
- nummeth-0.1.0/tests/test_roots.py +35 -0
nummeth-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Numerical Methods Lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
nummeth-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nummeth
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A practical, educational Numerical Methods library with iteration tables for laboratories and engineering.
|
|
5
|
+
Author: Numerical Methods Lab
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: numerical-methods,bisection,newton-raphson,gauss-elimination,interpolation,splines,runge-kutta,heat-equation,wave-equation,laplace-equation
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Education
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Provides-Extra: plot
|
|
24
|
+
Requires-Dist: matplotlib>=3.5.0; extra == "plot"
|
|
25
|
+
Provides-Extra: symbolic
|
|
26
|
+
Requires-Dist: sympy>=1.10.0; extra == "symbolic"
|
|
27
|
+
Provides-Extra: all
|
|
28
|
+
Requires-Dist: matplotlib>=3.5.0; extra == "all"
|
|
29
|
+
Requires-Dist: sympy>=1.10.0; extra == "all"
|
|
30
|
+
Requires-Dist: numpy>=1.20.0; extra == "all"
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
33
|
+
Requires-Dist: build; extra == "dev"
|
|
34
|
+
Requires-Dist: twine; extra == "dev"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# NumMeth (`nummeth`)
|
|
38
|
+
|
|
39
|
+
[](https://opensource.org/licenses/MIT)
|
|
40
|
+
[](https://pypi.org/project/nummeth/)
|
|
41
|
+
|
|
42
|
+
A practical, educational Numerical Methods library designed specifically for **university and engineering laboratories**.
|
|
43
|
+
|
|
44
|
+
Unlike generic scientific computing libraries that only return final values, `nummeth` is built for students and instructors:
|
|
45
|
+
- **Clean, intuitive APIs** mirroring standard textbooks.
|
|
46
|
+
- **Pre-formatted ASCII iteration tables** ready for copy-pasting into lab observation sheets and reports (`show_table=True` or `result.print_table()`).
|
|
47
|
+
- **Zero core dependencies** for effortless setup in lab computer networks.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install nummeth
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For optional plotting and symbolic mathematics support:
|
|
58
|
+
```bash
|
|
59
|
+
pip install nummeth[all]
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Features & Modules
|
|
65
|
+
|
|
66
|
+
### 1. Roots of Algebraic & Transcendental Equations
|
|
67
|
+
- **Bisection Method**: `nm.bisection(f, a, b, tol=1e-5, show_table=True)`
|
|
68
|
+
- **Regula-Falsi (False Position)**: `nm.false_position(f, a, b, tol=1e-5, show_table=True)`
|
|
69
|
+
- **Newton-Raphson Method**: `nm.newton_raphson(f, x0, df=None, tol=1e-5, show_table=True)`
|
|
70
|
+
- **Secant Method**: `nm.secant(f, x0, x1, tol=1e-5, show_table=True)`
|
|
71
|
+
- **Fixed-Point Iteration**: `nm.fixed_point(g, x0, tol=1e-5, show_table=True)`
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import nummeth as nm
|
|
75
|
+
|
|
76
|
+
f = lambda x: x**3 - x - 2
|
|
77
|
+
res = nm.bisection(f, a=1.0, b=2.0, tol=1e-4, show_table=True)
|
|
78
|
+
print(f"Computed root: {res.root}")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 2. Systems of Linear Equations & Eigenvalues
|
|
82
|
+
- **Gaussian Elimination** (with or without partial pivoting): `nm.gauss_elimination(A, b, pivoting=True)`
|
|
83
|
+
- **Gauss-Jacobi Iteration**: `nm.gauss_jacobi(A, b, show_table=True)`
|
|
84
|
+
- **Gauss-Seidel Iteration**: `nm.gauss_seidel(A, b, show_table=True)`
|
|
85
|
+
- **Matrix Inversion (Gauss-Jordan)**: `nm.matrix_inverse(A)`
|
|
86
|
+
- **Power Method (Dominant Eigenvalue & Eigenvector)**: `nm.power_method(A, show_table=True)`
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
A = [[10, -1, 2],
|
|
90
|
+
[-1, 11, -1],
|
|
91
|
+
[2, -1, 10]]
|
|
92
|
+
b = [6, 25, -11]
|
|
93
|
+
|
|
94
|
+
res = nm.gauss_seidel(A, b, show_table=True)
|
|
95
|
+
print("Solution:", res.solution)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 3. Interpolation & Splines
|
|
99
|
+
- **Lagrange Interpolation**: `nm.lagrange_interpolate(x, y, x_eval=6.5, symbolic=True)`
|
|
100
|
+
- **Newton's Divided Difference Table & Interpolation**: `nm.divided_difference_interp(x, y, x_eval=3.5, show_table=True)`
|
|
101
|
+
- **Newton Forward Difference Table & Interpolation**: `nm.newton_forward_interp(x, y, x_eval=0.2, show_table=True)`
|
|
102
|
+
- **Newton Backward Difference Table & Interpolation**: `nm.newton_backward_interp(x, y, x_eval=0.8, show_table=True)`
|
|
103
|
+
- **Natural Cubic Spline**: `nm.natural_cubic_spline(x, y, x_eval=2.5, plot=True)`
|
|
104
|
+
|
|
105
|
+
### 4. Least-Squares Curve Fitting
|
|
106
|
+
- **Polynomial Regression**: `nm.polynomial_fit(x, y, degree=1, plot=True)`
|
|
107
|
+
|
|
108
|
+
### 5. Numerical Calculus (Differentiation & Integration)
|
|
109
|
+
- **Finite Difference Derivatives**: `nm.derivative_central(f, x)`
|
|
110
|
+
- **Trapezoidal Rule**: `nm.trapezoidal(f, a, b, n)`
|
|
111
|
+
- **Simpson's 1/3 Rule**: `nm.simpson_13(f, a, b, n)`
|
|
112
|
+
- **Simpson's 3/8 Rule**: `nm.simpson_38(f, a, b, n)`
|
|
113
|
+
- **Boole's Rule**: `nm.boole(f, a, b, n)`
|
|
114
|
+
- **Weddle's Rule**: `nm.weddle(f, a, b, n)`
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
f = lambda x: 1.0 / (1.0 + x**2)
|
|
118
|
+
res = nm.simpson_13(f, a=0, b=1, n=6)
|
|
119
|
+
print(f"Integral = {res.value} (Approximating π/4)")
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### 6. Ordinary Differential Equations (Initial Value Problems)
|
|
123
|
+
- **Euler's Method**: `nm.euler(f, x0, y0, x_end, h, show_table=True)`
|
|
124
|
+
- **Modified Euler / Heun's Method**: `nm.modified_euler(f, x0, y0, x_end, h, show_table=True)`
|
|
125
|
+
- **Runge-Kutta 2nd Order (RK2)**: `nm.rk2(f, x0, y0, x_end, h, show_table=True)`
|
|
126
|
+
- **Runge-Kutta 4th Order (RK4)**: `nm.rk4(f, x0, y0, x_end, h, show_table=True)`
|
|
127
|
+
- **Milne's Predictor-Corrector**: `nm.milne_predictor_corrector(f, x0, y0, x_end, h, show_table=True)`
|
|
128
|
+
|
|
129
|
+
### 7. Finite Difference Methods for PDEs
|
|
130
|
+
- **Elliptic (Laplace / Poisson 2D)**: `nm.solve_laplace_2d(nx=4, ny=4, top=100, bottom=0, left=50, right=50)`
|
|
131
|
+
- **Parabolic (1D Heat Equation)**:
|
|
132
|
+
- Bender-Schmidt Explicit Scheme: `nm.heat_1d_bender_schmidt(...)`
|
|
133
|
+
- Crank-Nicolson Implicit Scheme: `nm.heat_1d_crank_nicolson(...)`
|
|
134
|
+
- **Hyperbolic (1D Wave Equation)**: `nm.wave_1d_explicit(...)`
|
|
135
|
+
|
|
136
|
+
### 8. Laboratory Applications
|
|
137
|
+
- **Circuit Nodal Voltage Solver**: `nm.solve_circuit_nodal(known_voltages, unknown_nodes, resistors)`
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Lab Source Preservation
|
|
142
|
+
The original lab reference scripts are preserved in the [`sources/`](sources/) directory.
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
MIT License. Free for educational and commercial use.
|
nummeth-0.1.0/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# NumMeth (`nummeth`)
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](https://pypi.org/project/nummeth/)
|
|
5
|
+
|
|
6
|
+
A practical, educational Numerical Methods library designed specifically for **university and engineering laboratories**.
|
|
7
|
+
|
|
8
|
+
Unlike generic scientific computing libraries that only return final values, `nummeth` is built for students and instructors:
|
|
9
|
+
- **Clean, intuitive APIs** mirroring standard textbooks.
|
|
10
|
+
- **Pre-formatted ASCII iteration tables** ready for copy-pasting into lab observation sheets and reports (`show_table=True` or `result.print_table()`).
|
|
11
|
+
- **Zero core dependencies** for effortless setup in lab computer networks.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install nummeth
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
For optional plotting and symbolic mathematics support:
|
|
22
|
+
```bash
|
|
23
|
+
pip install nummeth[all]
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Features & Modules
|
|
29
|
+
|
|
30
|
+
### 1. Roots of Algebraic & Transcendental Equations
|
|
31
|
+
- **Bisection Method**: `nm.bisection(f, a, b, tol=1e-5, show_table=True)`
|
|
32
|
+
- **Regula-Falsi (False Position)**: `nm.false_position(f, a, b, tol=1e-5, show_table=True)`
|
|
33
|
+
- **Newton-Raphson Method**: `nm.newton_raphson(f, x0, df=None, tol=1e-5, show_table=True)`
|
|
34
|
+
- **Secant Method**: `nm.secant(f, x0, x1, tol=1e-5, show_table=True)`
|
|
35
|
+
- **Fixed-Point Iteration**: `nm.fixed_point(g, x0, tol=1e-5, show_table=True)`
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import nummeth as nm
|
|
39
|
+
|
|
40
|
+
f = lambda x: x**3 - x - 2
|
|
41
|
+
res = nm.bisection(f, a=1.0, b=2.0, tol=1e-4, show_table=True)
|
|
42
|
+
print(f"Computed root: {res.root}")
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. Systems of Linear Equations & Eigenvalues
|
|
46
|
+
- **Gaussian Elimination** (with or without partial pivoting): `nm.gauss_elimination(A, b, pivoting=True)`
|
|
47
|
+
- **Gauss-Jacobi Iteration**: `nm.gauss_jacobi(A, b, show_table=True)`
|
|
48
|
+
- **Gauss-Seidel Iteration**: `nm.gauss_seidel(A, b, show_table=True)`
|
|
49
|
+
- **Matrix Inversion (Gauss-Jordan)**: `nm.matrix_inverse(A)`
|
|
50
|
+
- **Power Method (Dominant Eigenvalue & Eigenvector)**: `nm.power_method(A, show_table=True)`
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
A = [[10, -1, 2],
|
|
54
|
+
[-1, 11, -1],
|
|
55
|
+
[2, -1, 10]]
|
|
56
|
+
b = [6, 25, -11]
|
|
57
|
+
|
|
58
|
+
res = nm.gauss_seidel(A, b, show_table=True)
|
|
59
|
+
print("Solution:", res.solution)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 3. Interpolation & Splines
|
|
63
|
+
- **Lagrange Interpolation**: `nm.lagrange_interpolate(x, y, x_eval=6.5, symbolic=True)`
|
|
64
|
+
- **Newton's Divided Difference Table & Interpolation**: `nm.divided_difference_interp(x, y, x_eval=3.5, show_table=True)`
|
|
65
|
+
- **Newton Forward Difference Table & Interpolation**: `nm.newton_forward_interp(x, y, x_eval=0.2, show_table=True)`
|
|
66
|
+
- **Newton Backward Difference Table & Interpolation**: `nm.newton_backward_interp(x, y, x_eval=0.8, show_table=True)`
|
|
67
|
+
- **Natural Cubic Spline**: `nm.natural_cubic_spline(x, y, x_eval=2.5, plot=True)`
|
|
68
|
+
|
|
69
|
+
### 4. Least-Squares Curve Fitting
|
|
70
|
+
- **Polynomial Regression**: `nm.polynomial_fit(x, y, degree=1, plot=True)`
|
|
71
|
+
|
|
72
|
+
### 5. Numerical Calculus (Differentiation & Integration)
|
|
73
|
+
- **Finite Difference Derivatives**: `nm.derivative_central(f, x)`
|
|
74
|
+
- **Trapezoidal Rule**: `nm.trapezoidal(f, a, b, n)`
|
|
75
|
+
- **Simpson's 1/3 Rule**: `nm.simpson_13(f, a, b, n)`
|
|
76
|
+
- **Simpson's 3/8 Rule**: `nm.simpson_38(f, a, b, n)`
|
|
77
|
+
- **Boole's Rule**: `nm.boole(f, a, b, n)`
|
|
78
|
+
- **Weddle's Rule**: `nm.weddle(f, a, b, n)`
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
f = lambda x: 1.0 / (1.0 + x**2)
|
|
82
|
+
res = nm.simpson_13(f, a=0, b=1, n=6)
|
|
83
|
+
print(f"Integral = {res.value} (Approximating π/4)")
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 6. Ordinary Differential Equations (Initial Value Problems)
|
|
87
|
+
- **Euler's Method**: `nm.euler(f, x0, y0, x_end, h, show_table=True)`
|
|
88
|
+
- **Modified Euler / Heun's Method**: `nm.modified_euler(f, x0, y0, x_end, h, show_table=True)`
|
|
89
|
+
- **Runge-Kutta 2nd Order (RK2)**: `nm.rk2(f, x0, y0, x_end, h, show_table=True)`
|
|
90
|
+
- **Runge-Kutta 4th Order (RK4)**: `nm.rk4(f, x0, y0, x_end, h, show_table=True)`
|
|
91
|
+
- **Milne's Predictor-Corrector**: `nm.milne_predictor_corrector(f, x0, y0, x_end, h, show_table=True)`
|
|
92
|
+
|
|
93
|
+
### 7. Finite Difference Methods for PDEs
|
|
94
|
+
- **Elliptic (Laplace / Poisson 2D)**: `nm.solve_laplace_2d(nx=4, ny=4, top=100, bottom=0, left=50, right=50)`
|
|
95
|
+
- **Parabolic (1D Heat Equation)**:
|
|
96
|
+
- Bender-Schmidt Explicit Scheme: `nm.heat_1d_bender_schmidt(...)`
|
|
97
|
+
- Crank-Nicolson Implicit Scheme: `nm.heat_1d_crank_nicolson(...)`
|
|
98
|
+
- **Hyperbolic (1D Wave Equation)**: `nm.wave_1d_explicit(...)`
|
|
99
|
+
|
|
100
|
+
### 8. Laboratory Applications
|
|
101
|
+
- **Circuit Nodal Voltage Solver**: `nm.solve_circuit_nodal(known_voltages, unknown_nodes, resistors)`
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Lab Source Preservation
|
|
106
|
+
The original lab reference scripts are preserved in the [`sources/`](sources/) directory.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
MIT License. Free for educational and commercial use.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "nummeth"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A practical, educational Numerical Methods library with iteration tables for laboratories and engineering."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Numerical Methods Lab" }
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"numerical-methods",
|
|
17
|
+
"bisection",
|
|
18
|
+
"newton-raphson",
|
|
19
|
+
"gauss-elimination",
|
|
20
|
+
"interpolation",
|
|
21
|
+
"splines",
|
|
22
|
+
"runge-kutta",
|
|
23
|
+
"heat-equation",
|
|
24
|
+
"wave-equation",
|
|
25
|
+
"laplace-equation",
|
|
26
|
+
]
|
|
27
|
+
classifiers = [
|
|
28
|
+
"Development Status :: 4 - Beta",
|
|
29
|
+
"Intended Audience :: Education",
|
|
30
|
+
"Intended Audience :: Science/Research",
|
|
31
|
+
"Programming Language :: Python :: 3",
|
|
32
|
+
"Programming Language :: Python :: 3.8",
|
|
33
|
+
"Programming Language :: Python :: 3.9",
|
|
34
|
+
"Programming Language :: Python :: 3.10",
|
|
35
|
+
"Programming Language :: Python :: 3.11",
|
|
36
|
+
"Programming Language :: Python :: 3.12",
|
|
37
|
+
"Programming Language :: Python :: 3.13",
|
|
38
|
+
"Programming Language :: Python :: 3.14",
|
|
39
|
+
"Topic :: Scientific/Engineering :: Mathematics",
|
|
40
|
+
]
|
|
41
|
+
dependencies = []
|
|
42
|
+
|
|
43
|
+
[project.optional-dependencies]
|
|
44
|
+
plot = ["matplotlib>=3.5.0"]
|
|
45
|
+
symbolic = ["sympy>=1.10.0"]
|
|
46
|
+
all = [
|
|
47
|
+
"matplotlib>=3.5.0",
|
|
48
|
+
"sympy>=1.10.0",
|
|
49
|
+
"numpy>=1.20.0",
|
|
50
|
+
]
|
|
51
|
+
dev = [
|
|
52
|
+
"pytest>=7.0",
|
|
53
|
+
"build",
|
|
54
|
+
"twine",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
[tool.setuptools.packages.find]
|
|
58
|
+
where = ["src"]
|
nummeth-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""
|
|
2
|
+
NumMeth: A Practical, Educational Numerical Methods Library for Laboratories & Engineering.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
__version__ = "0.1.0"
|
|
6
|
+
|
|
7
|
+
# Core structures
|
|
8
|
+
from nummeth.core.results import IterationResult, TableFormatter
|
|
9
|
+
|
|
10
|
+
# 1. Algebraic & Transcendental Roots
|
|
11
|
+
from nummeth.roots import (
|
|
12
|
+
bisection,
|
|
13
|
+
false_position,
|
|
14
|
+
newton_raphson,
|
|
15
|
+
secant,
|
|
16
|
+
fixed_point,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
# 2. Linear Systems & Eigenvalues
|
|
20
|
+
from nummeth.linear_systems import (
|
|
21
|
+
gauss_elimination,
|
|
22
|
+
gauss_jacobi,
|
|
23
|
+
gauss_seidel,
|
|
24
|
+
matrix_inverse,
|
|
25
|
+
power_method,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
# 3. Interpolation & Splines
|
|
29
|
+
from nummeth.interpolation import (
|
|
30
|
+
lagrange_interpolate,
|
|
31
|
+
divided_difference_table,
|
|
32
|
+
divided_difference_interp,
|
|
33
|
+
newton_forward_table,
|
|
34
|
+
newton_forward_interp,
|
|
35
|
+
newton_backward_table,
|
|
36
|
+
newton_backward_interp,
|
|
37
|
+
natural_cubic_spline,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# 4. Curve Fitting & Regression
|
|
41
|
+
from nummeth.fitting import (
|
|
42
|
+
polynomial_fit,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
# 5. Numerical Calculus
|
|
46
|
+
from nummeth.calculus import (
|
|
47
|
+
derivative_forward,
|
|
48
|
+
derivative_backward,
|
|
49
|
+
derivative_central,
|
|
50
|
+
derivative_second,
|
|
51
|
+
trapezoidal,
|
|
52
|
+
simpson_13,
|
|
53
|
+
simpson_38,
|
|
54
|
+
boole,
|
|
55
|
+
weddle,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# 6. Ordinary Differential Equations (IVP)
|
|
59
|
+
from nummeth.ode import (
|
|
60
|
+
euler,
|
|
61
|
+
modified_euler,
|
|
62
|
+
rk2,
|
|
63
|
+
rk4,
|
|
64
|
+
milne_predictor_corrector,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
# 7. Partial Differential Equations (Finite Differences)
|
|
68
|
+
from nummeth.pde import (
|
|
69
|
+
solve_laplace_2d,
|
|
70
|
+
solve_poisson_2d,
|
|
71
|
+
heat_1d_bender_schmidt,
|
|
72
|
+
heat_1d_crank_nicolson,
|
|
73
|
+
wave_1d_explicit,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# 8. Applications
|
|
77
|
+
from nummeth.applications import (
|
|
78
|
+
solve_circuit_nodal,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
__all__ = [
|
|
82
|
+
"__version__",
|
|
83
|
+
"IterationResult",
|
|
84
|
+
"TableFormatter",
|
|
85
|
+
# Roots
|
|
86
|
+
"bisection",
|
|
87
|
+
"false_position",
|
|
88
|
+
"newton_raphson",
|
|
89
|
+
"secant",
|
|
90
|
+
"fixed_point",
|
|
91
|
+
# Linear
|
|
92
|
+
"gauss_elimination",
|
|
93
|
+
"gauss_jacobi",
|
|
94
|
+
"gauss_seidel",
|
|
95
|
+
"matrix_inverse",
|
|
96
|
+
"power_method",
|
|
97
|
+
# Interpolation
|
|
98
|
+
"lagrange_interpolate",
|
|
99
|
+
"divided_difference_table",
|
|
100
|
+
"divided_difference_interp",
|
|
101
|
+
"newton_forward_table",
|
|
102
|
+
"newton_forward_interp",
|
|
103
|
+
"newton_backward_table",
|
|
104
|
+
"newton_backward_interp",
|
|
105
|
+
"natural_cubic_spline",
|
|
106
|
+
# Fitting
|
|
107
|
+
"polynomial_fit",
|
|
108
|
+
# Calculus
|
|
109
|
+
"derivative_forward",
|
|
110
|
+
"derivative_backward",
|
|
111
|
+
"derivative_central",
|
|
112
|
+
"derivative_second",
|
|
113
|
+
"trapezoidal",
|
|
114
|
+
"simpson_13",
|
|
115
|
+
"simpson_38",
|
|
116
|
+
"boole",
|
|
117
|
+
"weddle",
|
|
118
|
+
# ODE
|
|
119
|
+
"euler",
|
|
120
|
+
"modified_euler",
|
|
121
|
+
"rk2",
|
|
122
|
+
"rk4",
|
|
123
|
+
"milne_predictor_corrector",
|
|
124
|
+
# PDE
|
|
125
|
+
"solve_laplace_2d",
|
|
126
|
+
"solve_poisson_2d",
|
|
127
|
+
"heat_1d_bender_schmidt",
|
|
128
|
+
"heat_1d_crank_nicolson",
|
|
129
|
+
"wave_1d_explicit",
|
|
130
|
+
# Applications
|
|
131
|
+
"solve_circuit_nodal",
|
|
132
|
+
]
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Electrical circuit nodal analysis application using systems of linear equations.
|
|
3
|
+
Ported from laboratory circuit solver exercise.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Dict, List, Tuple
|
|
7
|
+
from nummeth.core.results import IterationResult
|
|
8
|
+
from nummeth.linear_systems.elimination import gauss_elimination
|
|
9
|
+
|
|
10
|
+
def solve_circuit_nodal(
|
|
11
|
+
known_voltages: Dict[int, float],
|
|
12
|
+
unknown_nodes: List[int],
|
|
13
|
+
resistors: List[Tuple[int, int, float]],
|
|
14
|
+
method: str = "elimination"
|
|
15
|
+
) -> IterationResult:
|
|
16
|
+
"""
|
|
17
|
+
Solves for unknown node voltages and branch currents in a resistor network
|
|
18
|
+
using Kirchhoff's Current Law (Nodal Analysis).
|
|
19
|
+
|
|
20
|
+
Parameters:
|
|
21
|
+
known_voltages: Dict mapping node number -> known voltage (e.g. {1: 10.0, 6: 0.0}).
|
|
22
|
+
unknown_nodes: List of unknown node indices (e.g. [2, 3, 4, 5]).
|
|
23
|
+
resistors: List of tuples (node1, node2, resistance_in_ohms).
|
|
24
|
+
method: "elimination" or "seidel".
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
IterationResult where value is dict of all node voltages, and extra['branch_currents']
|
|
28
|
+
contains branch currents.
|
|
29
|
+
"""
|
|
30
|
+
n = len(unknown_nodes)
|
|
31
|
+
index = {node: i for i, node in enumerate(unknown_nodes)}
|
|
32
|
+
|
|
33
|
+
A = [[0.0 for _ in range(n)] for _ in range(n)]
|
|
34
|
+
b = [0.0 for _ in range(n)]
|
|
35
|
+
|
|
36
|
+
for node in unknown_nodes:
|
|
37
|
+
row = index[node]
|
|
38
|
+
for u, v, r in resistors:
|
|
39
|
+
if r <= 0:
|
|
40
|
+
raise ValueError("Resistance must be positive.")
|
|
41
|
+
if node == u:
|
|
42
|
+
other = v
|
|
43
|
+
elif node == v:
|
|
44
|
+
other = u
|
|
45
|
+
else:
|
|
46
|
+
continue
|
|
47
|
+
|
|
48
|
+
g = 1.0 / r
|
|
49
|
+
A[row][row] += g
|
|
50
|
+
|
|
51
|
+
if other in index:
|
|
52
|
+
A[row][index[other]] -= g
|
|
53
|
+
elif other in known_voltages:
|
|
54
|
+
b[row] += g * known_voltages[other]
|
|
55
|
+
|
|
56
|
+
# Solve linear system
|
|
57
|
+
sol_res = gauss_elimination(A, b, pivoting=True)
|
|
58
|
+
voltages = dict(known_voltages)
|
|
59
|
+
for i, node in enumerate(unknown_nodes):
|
|
60
|
+
voltages[node] = sol_res.value[i]
|
|
61
|
+
|
|
62
|
+
# Calculate branch currents
|
|
63
|
+
branch_currents = []
|
|
64
|
+
for u, v, r in resistors:
|
|
65
|
+
cur = (voltages[u] - voltages[v]) / r
|
|
66
|
+
branch_currents.append({"from": u, "to": v, "resistance": r, "current": cur})
|
|
67
|
+
|
|
68
|
+
return IterationResult(
|
|
69
|
+
value=voltages,
|
|
70
|
+
converged=True,
|
|
71
|
+
message="Circuit nodal voltages and currents resolved successfully.",
|
|
72
|
+
extra={
|
|
73
|
+
"voltages": voltages,
|
|
74
|
+
"branch_currents": branch_currents,
|
|
75
|
+
"conductance_matrix": A,
|
|
76
|
+
"rhs_vector": b
|
|
77
|
+
}
|
|
78
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Numerical calculus: differentiation and integration."""
|
|
2
|
+
from .differentiation import (
|
|
3
|
+
derivative_forward,
|
|
4
|
+
derivative_backward,
|
|
5
|
+
derivative_central,
|
|
6
|
+
derivative_second,
|
|
7
|
+
)
|
|
8
|
+
from .integration import (
|
|
9
|
+
trapezoidal,
|
|
10
|
+
simpson_13,
|
|
11
|
+
simpson_38,
|
|
12
|
+
boole,
|
|
13
|
+
weddle,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"derivative_forward",
|
|
18
|
+
"derivative_backward",
|
|
19
|
+
"derivative_central",
|
|
20
|
+
"derivative_second",
|
|
21
|
+
"trapezoidal",
|
|
22
|
+
"simpson_13",
|
|
23
|
+
"simpson_38",
|
|
24
|
+
"boole",
|
|
25
|
+
"weddle",
|
|
26
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Numerical Differentiation using finite difference formulas.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from typing import Callable, Union, List
|
|
6
|
+
|
|
7
|
+
def derivative_forward(f: Callable[[float], float], x: float, h: float = 1e-5) -> float:
|
|
8
|
+
"""First derivative via 2-point forward difference: f'(x) ≈ (f(x + h) - f(x)) / h"""
|
|
9
|
+
return (f(x + h) - f(x)) / h
|
|
10
|
+
|
|
11
|
+
def derivative_backward(f: Callable[[float], float], x: float, h: float = 1e-5) -> float:
|
|
12
|
+
"""First derivative via 2-point backward difference: f'(x) ≈ (f(x) - f(x - h)) / h"""
|
|
13
|
+
return (f(x) - f(x - h)) / h
|
|
14
|
+
|
|
15
|
+
def derivative_central(f: Callable[[float], float], x: float, h: float = 1e-5) -> float:
|
|
16
|
+
"""First derivative via 2-point central difference (O(h^2)): f'(x) ≈ (f(x + h) - f(x - h)) / (2h)"""
|
|
17
|
+
return (f(x + h) - f(x - h)) / (2.0 * h)
|
|
18
|
+
|
|
19
|
+
def derivative_second(f: Callable[[float], float], x: float, h: float = 1e-4) -> float:
|
|
20
|
+
"""Second derivative via central difference: f''(x) ≈ (f(x + h) - 2f(x) + f(x - h)) / h^2"""
|
|
21
|
+
return (f(x + h) - 2.0 * f(x) + f(x - h)) / (h ** 2)
|