openum 0.9.5__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.
- openum-0.9.5/LICENSE.md +21 -0
- openum-0.9.5/PKG-INFO +474 -0
- openum-0.9.5/README.md +455 -0
- openum-0.9.5/openum/BVP.py +112 -0
- openum-0.9.5/openum/Errorcalc.py +64 -0
- openum-0.9.5/openum/Interpolation.py +68 -0
- openum-0.9.5/openum/MC.py +61 -0
- openum-0.9.5/openum/NonLinEq.py +258 -0
- openum-0.9.5/openum/NumEigenv.py +142 -0
- openum-0.9.5/openum/NumLinEqu.py +222 -0
- openum-0.9.5/openum/ODE.py +295 -0
- openum-0.9.5/openum/PDE.py +234 -0
- openum-0.9.5/openum/__init__.py +11 -0
- openum-0.9.5/openum/numdiff.py +95 -0
- openum-0.9.5/openum/numint.py +217 -0
- openum-0.9.5/openum.egg-info/PKG-INFO +474 -0
- openum-0.9.5/openum.egg-info/SOURCES.txt +29 -0
- openum-0.9.5/openum.egg-info/dependency_links.txt +1 -0
- openum-0.9.5/openum.egg-info/requires.txt +2 -0
- openum-0.9.5/openum.egg-info/top_level.txt +1 -0
- openum-0.9.5/pyproject.toml +28 -0
- openum-0.9.5/setup.cfg +4 -0
- openum-0.9.5/tests/test_BVP.py +46 -0
- openum-0.9.5/tests/test_Eigenv.py +73 -0
- openum-0.9.5/tests/test_Errorcalc.py +75 -0
- openum-0.9.5/tests/test_MC.py +51 -0
- openum-0.9.5/tests/test_NonLinEqu.py +125 -0
- openum-0.9.5/tests/test_NumLinEqu.py +162 -0
- openum-0.9.5/tests/test_ODE.py +168 -0
- openum-0.9.5/tests/test_PDE.py +70 -0
- openum-0.9.5/tests/test_numint.py +72 -0
openum-0.9.5/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tim Peinkofer
|
|
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.
|
openum-0.9.5/PKG-INFO
ADDED
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: openum
|
|
3
|
+
Version: 0.9.5
|
|
4
|
+
Summary: A simple Python library for numerical mathematical calculations and its utility functions.
|
|
5
|
+
Author-email: Tim Peinkofer <tim.peinkofer@student.uni-tuebingen.de>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/TimPeinkofer/openum
|
|
8
|
+
Project-URL: Bug-Tracker, https://github.com/TimPeinkofer/openum/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE.md
|
|
16
|
+
Requires-Dist: numpy
|
|
17
|
+
Requires-Dist: matplotlib
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# openum
|
|
21
|
+
|
|
22
|
+
[](https://github.com/TimPeinkofer/openum/actions/workflows/ci.yml)
|
|
23
|
+
|
|
24
|
+
## Why openum?
|
|
25
|
+
|
|
26
|
+
While giant libraries like SciPy provide powerful "black-box" solvers optimized in C, **openum** bridges the gap between complex engineering and educational clarity.
|
|
27
|
+
|
|
28
|
+
* **Pure Python & Readable:** No obscured code. openum implements classic, transparent textbook algorithms (from *Newton-Halley* and *Aitken acceleration* to *Adams Predictor-Corrector* and *PDE solvers*) that you can actually read, learn from, and debug.
|
|
29
|
+
* **Batteries Included (Built-in Plots):** Forget writing repetitive boilerplate code. openum solvers come with integrated visual plotting capabilities (`plotchoose`) out of the box, allowing you to visualize ODE trajectories and numerical results instantly.
|
|
30
|
+
* **All-in-One Educational Toolkit:** Instead of importing dozens of sub-modules, openum unifies the entire roadmap of numerical mathematics—linear algebra, interpolation, integration, differentiation, BVPs, and PDEs—under a single, intuitive, and beginner-friendly API.
|
|
31
|
+
|
|
32
|
+
> **openum is the lightweight, didactic alternative for students, engineers, and developers who don't just want a number, but want to understand the physics and math behind the solution.**
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
Thanks to the modern package configuration, `numpy` and `matplotlib` will be installed automatically as dependencies.
|
|
38
|
+
|
|
39
|
+
### Option 1: Direct Installation (Recommended for Users)
|
|
40
|
+
You can install the library directly from GitHub using `pip`:
|
|
41
|
+
```bash
|
|
42
|
+
pip install git+[https://github.com/TimPeinkofer/openum.git](https://github.com/TimPeinkofer/openum.git)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Option 2: Local Installation (For Developers)
|
|
46
|
+
If you want to modify the code, clone the repository and install it in editable mode:
|
|
47
|
+
```bash
|
|
48
|
+
git clone [https://github.com/TimPeinkofer/openum.git](https://github.com/TimPeinkofer/openum.git)
|
|
49
|
+
cd openum
|
|
50
|
+
pip install -e .
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Overview
|
|
54
|
+
The following types of numerical problems are addressed in this library:
|
|
55
|
+
|
|
56
|
+
1. Nonlinear equations
|
|
57
|
+
2. Systems of linear equations
|
|
58
|
+
3. Eigenvalue and Matrix calculations
|
|
59
|
+
4. Interpolation
|
|
60
|
+
5. Integration
|
|
61
|
+
6. Differentiation
|
|
62
|
+
7. Ordinary differential equations (Documentation in work
|
|
63
|
+
8. Boundary and Initial value problems
|
|
64
|
+
9. Hyperbolic, Parabolic and Elliptic Partial differential equations
|
|
65
|
+
10. Monte-Carlo-Integration (Documentation in work)
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Modules and Features
|
|
70
|
+
|
|
71
|
+
### 1. Nonlinear Equations
|
|
72
|
+
Methods to find the roots of nonlinear functions or systems.
|
|
73
|
+
|
|
74
|
+
#### `newtons_method(f, df, x0, max_iter, epsilon=1e-6)`
|
|
75
|
+
Finds the root of a function using Newton's method.
|
|
76
|
+
- **Args:**
|
|
77
|
+
- `f`: Function to find the root for.
|
|
78
|
+
- `df`: Derivative of the function.
|
|
79
|
+
- `x0`: Initial guess.
|
|
80
|
+
- `max_iter`: Maximum number of iterations.
|
|
81
|
+
- `epsilon`: Convergence criterion.
|
|
82
|
+
- **Returns:**
|
|
83
|
+
- `float`: Approximation of the root (or None if no convergence).
|
|
84
|
+
|
|
85
|
+
#### `linear_interpolation(f, x0, x1, max_iter, epsilon=1e-6)`
|
|
86
|
+
Finds the root of a function using linear interpolation (Secant method).
|
|
87
|
+
- **Args:**
|
|
88
|
+
- `f`: Function to find the root for.
|
|
89
|
+
- `x0`, `x1`: Initial guesses.
|
|
90
|
+
- `max_iter`: Maximum number of iterations.
|
|
91
|
+
- `epsilon`: Convergence criterion.
|
|
92
|
+
- **Returns:**
|
|
93
|
+
- `float`: Approximation of the root.
|
|
94
|
+
|
|
95
|
+
#### `solve_fixed_point(f1, f2, x_init, y_init, max_iter, tol=1e-8)`
|
|
96
|
+
Solves a system of two equations using fixed-point iteration.
|
|
97
|
+
- **Args:**
|
|
98
|
+
- `f1`, `f2`: Functions for the equations.
|
|
99
|
+
- `x_init`, `y_init`: Initial guesses.
|
|
100
|
+
- `max_iter`: Maximum iterations.
|
|
101
|
+
- `tol`: Convergence tolerance.
|
|
102
|
+
- **Returns:**
|
|
103
|
+
- `tuple`: Approximations of the roots `(x, y)`.
|
|
104
|
+
|
|
105
|
+
#### `newton_halley(f, df, d2f, x0, max_iter, epsilon=1e-6)`
|
|
106
|
+
Finds the root of a function using the Newton-Halley method.
|
|
107
|
+
- **Args:**
|
|
108
|
+
- `f`: Function to evaluate.
|
|
109
|
+
- `df`, `d2f`: First and second derivatives of the function.
|
|
110
|
+
- `x0`: Initial guess.
|
|
111
|
+
- `max_iter`: Maximum number of iterations.
|
|
112
|
+
- `epsilon`: Convergence criterion.
|
|
113
|
+
- **Returns:**
|
|
114
|
+
- `float`: Approximation of the root.
|
|
115
|
+
|
|
116
|
+
#### `bisection_method(x1, x2, f, max_iter, eps=1e-6)`
|
|
117
|
+
Finds the root of a function using the bisection method.
|
|
118
|
+
- **Args:**
|
|
119
|
+
- `x1`, `x2`: Lower and upper bounds of the interval.
|
|
120
|
+
- `f`: Function to evaluate.
|
|
121
|
+
- `max_iter`: Maximum number of iterations.
|
|
122
|
+
- `eps`: Convergence criterion.
|
|
123
|
+
- **Returns:**
|
|
124
|
+
- `float`: Approximation of the root.
|
|
125
|
+
|
|
126
|
+
#### `jacobi_method(A, b, init_val, max_iter, tol=1e-6)`
|
|
127
|
+
Solves a linear system using the iterative **Jacobi method**.
|
|
128
|
+
- **Args:**
|
|
129
|
+
- `A`: Coefficient matrix `(N x N)`.
|
|
130
|
+
- `b`: Right-hand side vector `(N,)`.
|
|
131
|
+
- `init_val`: Initial guess for the solution.
|
|
132
|
+
- `max_iter`: Maximum number of iterations.
|
|
133
|
+
- `tol`: Convergence tolerance.
|
|
134
|
+
- **Returns:**
|
|
135
|
+
- `ndarray`: Solution vector `(N,)`.
|
|
136
|
+
|
|
137
|
+
#### `gauss_seidel(m, vector, init_val, max_iter, tol=1e-6)`
|
|
138
|
+
Solves a linear system using the iterative **Gauss-Seidel method**.
|
|
139
|
+
- **Args:**
|
|
140
|
+
- `m`: Coefficient matrix `(N x N)`.
|
|
141
|
+
- `vector`: Right-hand side vector `(N,)`.
|
|
142
|
+
- `init_val`: Initial guess.
|
|
143
|
+
- `max_iter`: Maximum number of iterations.
|
|
144
|
+
- `tol`: Convergence tolerance.
|
|
145
|
+
- **Returns:**
|
|
146
|
+
- `ndarray`: Solution vector `(N,)`.
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
### 2. Systems of Linear Equations
|
|
151
|
+
Direct and iterative methods for solving $Ax = b$ and matrix operations.
|
|
152
|
+
|
|
153
|
+
#### `Gauss_elimination(matrix, vector)`
|
|
154
|
+
Solves a linear system using standard Gaussian elimination.
|
|
155
|
+
- **Args:**
|
|
156
|
+
- `matrix`: Coefficient matrix `(N x N)`.
|
|
157
|
+
- `vector`: Right-hand side vector `(N,)`.
|
|
158
|
+
- **Returns:**
|
|
159
|
+
- `ndarray`: Solution vector `(N,)`.
|
|
160
|
+
|
|
161
|
+
#### `Gauss_elimination_pivoted(matrix, vector)`
|
|
162
|
+
Solves a linear system using Gaussian elimination with **partial pivoting** to minimize numerical errors.
|
|
163
|
+
- **Args:**
|
|
164
|
+
- `matrix`: Coefficient matrix `(N x N)`.
|
|
165
|
+
- `vector`: Right-hand side vector `(N,)`.
|
|
166
|
+
- **Returns:**
|
|
167
|
+
- `ndarray`: Solution vector `(N,)`.
|
|
168
|
+
|
|
169
|
+
#### `Gauss_Jordan(A)`
|
|
170
|
+
Performs Gauss-Jordan elimination.
|
|
171
|
+
- **Args:**
|
|
172
|
+
- `A`: The augmented matrix to be reduced.
|
|
173
|
+
- **Returns:**
|
|
174
|
+
- `ndarray`: Reduced row echelon form of the matrix.
|
|
175
|
+
|
|
176
|
+
#### `inverse_matrix(A)`
|
|
177
|
+
Calculates the inverse of a square matrix using Gauss-Jordan elimination.
|
|
178
|
+
- **Args:**
|
|
179
|
+
- `A`: Input matrix.
|
|
180
|
+
- **Returns:**
|
|
181
|
+
- `ndarray`: Inverse of the matrix.
|
|
182
|
+
|
|
183
|
+
#### `determinant(matrix)`
|
|
184
|
+
Calculates the determinant of a square matrix.
|
|
185
|
+
- **Args:**
|
|
186
|
+
- `matrix`: Base matrix.
|
|
187
|
+
- **Returns:**
|
|
188
|
+
- `float`: Value of the determinant.
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
#### `overrelaxation(A, b, Max_iterations)`
|
|
193
|
+
Finds the optimal solution using **Successive Over-Relaxation (SOR)** by evaluating different relaxation factors.
|
|
194
|
+
- **Args:**
|
|
195
|
+
- `A`: Coefficient matrix.
|
|
196
|
+
- `b`: Right-hand side vector.
|
|
197
|
+
- `Max_iterations`: Maximum iterations per factor.
|
|
198
|
+
- **Returns:**
|
|
199
|
+
- `ndarray`: Best solution vector found.
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
### 3. Eigenvalue and Eigenvector Computation
|
|
204
|
+
Methods for computing eigenvalues and eigenvectors using power iteration and Aitken's acceleration.
|
|
205
|
+
|
|
206
|
+
#### `Eigenvalue_calc(mat, vec, Iteration)`
|
|
207
|
+
Computes the dominant eigenvalue and eigenvector using the **power iteration method**.
|
|
208
|
+
- **Args:**
|
|
209
|
+
- `mat`: Input matrix.
|
|
210
|
+
- `vec`: Initial guess vector.
|
|
211
|
+
- `Iteration`: Number of iterations.
|
|
212
|
+
- **Returns:**
|
|
213
|
+
- `tuple`: `(eigenvalue, eigenvector)`.
|
|
214
|
+
|
|
215
|
+
#### `Eigenvalues(mat, vec, Iteration)`
|
|
216
|
+
Computes the largest and smallest eigenvalues (using the matrix inverse).
|
|
217
|
+
- **Args:**
|
|
218
|
+
- `mat`: Input matrix.
|
|
219
|
+
- `vec`: Initial guess vector.
|
|
220
|
+
- `Iteration`: Number of iterations.
|
|
221
|
+
- **Returns:**
|
|
222
|
+
- `tuple`: List of eigenvalues and list of eigenvectors.
|
|
223
|
+
|
|
224
|
+
#### `Aitken(Eigenvalues)`
|
|
225
|
+
Applies **Aitken’s delta-squared process** to accelerate convergence.
|
|
226
|
+
- **Args:**
|
|
227
|
+
- `Eigenvalues`: Sequence of approximated eigenvalues.
|
|
228
|
+
- **Returns:**
|
|
229
|
+
- `float`: Accelerated eigenvalue.
|
|
230
|
+
|
|
231
|
+
#### `eigenvalue_calc_aitken(mat, vec, Iteration)`
|
|
232
|
+
Computes the dominant eigenvalue and eigenvector using power iteration with Aitken acceleration.
|
|
233
|
+
- **Args:**
|
|
234
|
+
- `mat`: Input matrix.
|
|
235
|
+
- `vec`: Initial guess vector.
|
|
236
|
+
- `Iteration`: Number of iterations.
|
|
237
|
+
- **Returns:**
|
|
238
|
+
- `tuple`: `(eigenvalue, eigenvector)`.
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
### 4. Interpolation
|
|
243
|
+
Algorithms for smooth data interpolation.
|
|
244
|
+
|
|
245
|
+
#### `cubic_splines(n, x, func)`
|
|
246
|
+
Constructs cubic splines for interpolation across a set of points.
|
|
247
|
+
- **Args:**
|
|
248
|
+
- `n`: Number of intervals.
|
|
249
|
+
- `x`: Array of grid points.
|
|
250
|
+
- `func`: Function to evaluate at grid points.
|
|
251
|
+
- **Returns:**
|
|
252
|
+
- `tuple`: `(matrix, vec, solution)` containing the spline system and second derivatives.
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
### 5. Numerical Integration
|
|
257
|
+
Methods to approximate definite integrals.
|
|
258
|
+
|
|
259
|
+
#### `Simpson_1_3(n, a, b, func)`
|
|
260
|
+
Calculates the integral using Simpson's 1/3 rule.
|
|
261
|
+
- **Args:**
|
|
262
|
+
- `n`: Number of subintervals.
|
|
263
|
+
- `a`, `b`: Lower and upper bounds.
|
|
264
|
+
- `func`: Function to integrate.
|
|
265
|
+
- **Returns:**
|
|
266
|
+
- `float`: Approximated integral.
|
|
267
|
+
|
|
268
|
+
#### `Romberg(n, a, b, func)`
|
|
269
|
+
Calculates the integral using Romberg integration.
|
|
270
|
+
- **Args:**
|
|
271
|
+
- `n`: Number of subintervals.
|
|
272
|
+
- `a`, `b`: Lower and upper bounds.
|
|
273
|
+
- `func`: Function to integrate.
|
|
274
|
+
- **Returns:**
|
|
275
|
+
- `float`: Approximated integral.
|
|
276
|
+
|
|
277
|
+
#### `Gauss_legendre(a, b, n, func)`
|
|
278
|
+
Calculates the integral using Gauss-Legendre quadrature (up to 5 points).
|
|
279
|
+
- **Args:**
|
|
280
|
+
- `a`, `b`: Lower and upper bounds.
|
|
281
|
+
- `n`: Number of points (1 to 5).
|
|
282
|
+
- `func`: Function to integrate.
|
|
283
|
+
- **Returns:**
|
|
284
|
+
- `float`: Approximated integral.
|
|
285
|
+
|
|
286
|
+
#### `Newton_cotes(n, a, b, func)`
|
|
287
|
+
Calculates the integral using the Newton-Cotes formula.
|
|
288
|
+
- **Args:**
|
|
289
|
+
- `n`: Number of subintervals.
|
|
290
|
+
- `a`, `b`: Lower and upper bounds.
|
|
291
|
+
- `func`: Function to integrate.
|
|
292
|
+
- **Returns:**
|
|
293
|
+
- `float`: Approximated integral.
|
|
294
|
+
|
|
295
|
+
#### `Trapezoidal(n, a, b, func)`
|
|
296
|
+
Calculates the integral using the Trapezoidal rule.
|
|
297
|
+
- **Args:**
|
|
298
|
+
- `n`: Number of subintervals.
|
|
299
|
+
- `a`, `b`: Lower and upper bounds.
|
|
300
|
+
- `func`: Function to integrate.
|
|
301
|
+
- **Returns:**
|
|
302
|
+
- `float`: Approximated integral.
|
|
303
|
+
|
|
304
|
+
#### `Simpson_3_8(n, a, b, func)`
|
|
305
|
+
Calculates the integral using Simpson's 3/8 rule.
|
|
306
|
+
- **Args:**
|
|
307
|
+
- `n`: Number of subintervals.
|
|
308
|
+
- `a`, `b`: Lower and upper bounds.
|
|
309
|
+
- `func`: Function to integrate.
|
|
310
|
+
- **Returns:**
|
|
311
|
+
- `float`: Approximated integral.
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
### 6. Numerical Differentiation Methods
|
|
316
|
+
|
|
317
|
+
#### `Central_diff_first_deri(x, h, func)`
|
|
318
|
+
Computes the first derivative using 4th-order central differences.
|
|
319
|
+
- **Args:**
|
|
320
|
+
- `x`: Point to evaluate.
|
|
321
|
+
- `h`: Step size.
|
|
322
|
+
- `func`: Function to differentiate.
|
|
323
|
+
- **Returns:**
|
|
324
|
+
- `float`: Derivative at `x`.
|
|
325
|
+
|
|
326
|
+
#### `Richardson(x, h, func)`
|
|
327
|
+
Computes the derivative using Richardson extrapolation.
|
|
328
|
+
- **Args:**
|
|
329
|
+
- `x`: Point to evaluate.
|
|
330
|
+
- `h`: Step size.
|
|
331
|
+
- `func`: Function to differentiate.
|
|
332
|
+
- **Returns:**
|
|
333
|
+
- `float`: Extrapolated derivative.
|
|
334
|
+
|
|
335
|
+
#### `spline_derivative(i, x_val, x, func)`
|
|
336
|
+
Computes the derivative using cubic spline interpolation.
|
|
337
|
+
- **Args:**
|
|
338
|
+
- `i`: Index of the interval.
|
|
339
|
+
- `x_val`: Evaluation point.
|
|
340
|
+
- `x`: Grid points.
|
|
341
|
+
- `func`: Function.
|
|
342
|
+
- **Returns:**
|
|
343
|
+
- `float`: Derivative of the spline.
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
### 7. Numerical ODE Solvers
|
|
348
|
+
Algorithms for solving ordinary differential equations and systems.
|
|
349
|
+
|
|
350
|
+
#### `Heun(x0, xm, y0, n, f, plotchoose)`
|
|
351
|
+
Solves an ODE using Heun’s method (2nd order).
|
|
352
|
+
- **Args:**
|
|
353
|
+
- `x0`, `xm`: Initial and final x values.
|
|
354
|
+
- `y0`: Initial y value.
|
|
355
|
+
- `n`: Number of steps.
|
|
356
|
+
- `f`: Derivative function `f(x, y)`.
|
|
357
|
+
- `plotchoose`: Boolean to plot the result.
|
|
358
|
+
- **Returns:**
|
|
359
|
+
- `tuple`: `(x_values, y_values)`.
|
|
360
|
+
|
|
361
|
+
#### `adam_ode_int(f, y_0, x0, xm, n, plotchoose)`
|
|
362
|
+
Solves an ODE using the **Adams Predictor-Corrector** method.
|
|
363
|
+
- **Args:**
|
|
364
|
+
- `f`: Derivative function.
|
|
365
|
+
- `y_0`: Initial y value.
|
|
366
|
+
- `x0`, `xm`: Initial and final x values.
|
|
367
|
+
- `n`: Number of steps.
|
|
368
|
+
- `plotchoose`: Boolean to plot the result.
|
|
369
|
+
- **Returns:**
|
|
370
|
+
- `tuple`: `(y_corrected, y_predicted)`.
|
|
371
|
+
|
|
372
|
+
#### `Adam(x0, xm, y0, n, f, plotchoose)`
|
|
373
|
+
Solves an ODE using the classical Adams method.
|
|
374
|
+
- **Args:**
|
|
375
|
+
- `x0`, `xm`: Initial and final x values.
|
|
376
|
+
- `y0`: Initial y value.
|
|
377
|
+
- `n`: Number of steps.
|
|
378
|
+
- `f`: Derivative function.
|
|
379
|
+
- `plotchoose`: Boolean to plot the result.
|
|
380
|
+
- **Returns:**
|
|
381
|
+
- `tuple`: `(x_values, y_values)`.
|
|
382
|
+
|
|
383
|
+
#### `runge_kutta(x_start, x_end, y_0, n, f, plotchoose)`
|
|
384
|
+
Solves an ODE using the **Runge-Kutta 4th order** method.
|
|
385
|
+
- **Args:**
|
|
386
|
+
- `x_start`, `x_end`: Initial and final x values.
|
|
387
|
+
- `y_0`: Initial y value.
|
|
388
|
+
- `n`: Number of steps.
|
|
389
|
+
- `f`: Derivative function.
|
|
390
|
+
- `plotchoose`: Boolean to plot the result.
|
|
391
|
+
- **Returns:**
|
|
392
|
+
- `tuple`: `(x_values, y_values)`.
|
|
393
|
+
|
|
394
|
+
#### `systems_of_ODE(system, y0, t)`
|
|
395
|
+
Solves a system of ODEs using the Runge-Kutta 4th order algorithm.
|
|
396
|
+
- **Args:**
|
|
397
|
+
- `system`: ODE equation system function.
|
|
398
|
+
- `y0`: List of initial conditions.
|
|
399
|
+
- `t`: Array/List of time steps.
|
|
400
|
+
- **Returns:**
|
|
401
|
+
- `ndarray`: Solution matrix `y`.
|
|
402
|
+
|
|
403
|
+
---
|
|
404
|
+
|
|
405
|
+
### 8. Boundary Value Problem Solver
|
|
406
|
+
|
|
407
|
+
#### `Matrix_method(x0, xn, n, y0, yn)`
|
|
408
|
+
Solves a BVP using the **finite difference** (matrix) method.
|
|
409
|
+
- **Args:**
|
|
410
|
+
- `x0`, `xn`: Left and right boundaries.
|
|
411
|
+
- `n`: Number of interior points.
|
|
412
|
+
- `y0`, `yn`: Boundary values.
|
|
413
|
+
- **Returns:**
|
|
414
|
+
- `ndarray`: Solution values at the grid points.
|
|
415
|
+
|
|
416
|
+
#### `solve_by_shooting(ode, x_1, x_2, n, v_0, u_1, u_2, max_iter)`
|
|
417
|
+
Solves a BVP using the **shooting method**.
|
|
418
|
+
- **Args:**
|
|
419
|
+
- `ode`: ODE system function.
|
|
420
|
+
- `x_1`, `x_2`: Domain boundaries.
|
|
421
|
+
- `n`: Number of grid points.
|
|
422
|
+
- `v_0`: Initial guesses for the derivative.
|
|
423
|
+
- `u_1`, `u_2`: Boundary values.
|
|
424
|
+
- `max_iter`: Maximum iterations for root finding.
|
|
425
|
+
- **Returns:**
|
|
426
|
+
- `tuple`: `(corrected_v, x_values, y_values)`.
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
430
|
+
### 9. Partial Differential Equations (PDE)
|
|
431
|
+
|
|
432
|
+
#### `elliptic_solver_laplace_2D(bc, h, x_bounds, y_bounds, g, maxiter)`
|
|
433
|
+
Solves the 2D Laplace/Poisson equation using Gauss-Seidel.
|
|
434
|
+
- **Args:**
|
|
435
|
+
- `bc`: Boundary conditions `[bottom, top, left, right]`.
|
|
436
|
+
- `h`: Grid spacing.
|
|
437
|
+
- `x_bounds`, `y_bounds`: Domain limits.
|
|
438
|
+
- `g`: Source term function (default=0).
|
|
439
|
+
- `maxiter`: Iteration count.
|
|
440
|
+
- **Returns:**
|
|
441
|
+
- `tuple`: `(u, x_values, y_values)`.
|
|
442
|
+
|
|
443
|
+
#### `elliptic_solver_laplace_3D(bc, h, x_bounds, y_bounds, z_bounds, g, maxiter)`
|
|
444
|
+
Solves the 3D Laplace/Poisson equation.
|
|
445
|
+
- **Args:**
|
|
446
|
+
- `bc`: Boundary conditions `[bottom, top, left, right, front, back]`.
|
|
447
|
+
- `h`: Grid spacing.
|
|
448
|
+
- `x_bounds`, `y_bounds`, `z_bounds`: Domain limits.
|
|
449
|
+
- `g`: Source term function.
|
|
450
|
+
- `maxiter`: Iteration count.
|
|
451
|
+
- **Returns:**
|
|
452
|
+
- `tuple`: `(u, x_values, y_values, z_values)`.
|
|
453
|
+
|
|
454
|
+
#### `parabolic_explicit_solver(x_bounds, t_bounds, bc_t, func, h, alpha)`
|
|
455
|
+
Explicit finite difference solver for the 1D heat equation.
|
|
456
|
+
- **Args:**
|
|
457
|
+
- `x_bounds`, `t_bounds`: Spatial and time intervals.
|
|
458
|
+
- `bc_t`: Boundary conditions over time.
|
|
459
|
+
- `func`: Initial profile `u(x, 0)`.
|
|
460
|
+
- `h`: Spatial step size.
|
|
461
|
+
- `alpha`: Diffusion coefficient.
|
|
462
|
+
- **Returns:**
|
|
463
|
+
- `tuple`: `(u, x_values, t_values)`.
|
|
464
|
+
|
|
465
|
+
#### `hyperbolic_solver(x_bounds, t_bounds, bc_t, func, h, alpha)`
|
|
466
|
+
Solver for the 1D wave equation.
|
|
467
|
+
- **Args:**
|
|
468
|
+
- `x_bounds`, `t_bounds`: Spatial and time intervals.
|
|
469
|
+
- `bc_t`: Boundary conditions over time.
|
|
470
|
+
- `func`: Initial profile `u(x, 0)`.
|
|
471
|
+
- `h`: Spatial step size.
|
|
472
|
+
- `alpha`: Wave speed.
|
|
473
|
+
- **Returns:**
|
|
474
|
+
- `tuple`: `(u, x_values, t_values)`.
|