numODEsolver 0.5.2__tar.gz → 2.0.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.
@@ -1,7 +1,7 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: numODEsolver
3
- Version: 0.5.2
4
- Summary: Tool that solves and plots ODE's numerically. Written in Python.
3
+ Version: 2.0.0
4
+ Summary: Tool that solves ODE's numerically. Written in Python.
5
5
  Home-page: https://github.com/lukasnf/Numerical-ODE-Solver
6
6
  Classifier: Programming Language :: Python :: 3
7
7
  Classifier: License :: OSI Approved :: MIT License
@@ -10,12 +10,20 @@ Requires-Python: >=3.8
10
10
  Description-Content-Type: text/markdown
11
11
  License-File: LICENSE
12
12
  Requires-Dist: numpy
13
- Requires-Dist: sympy
13
+ Requires-Dist: asteval
14
14
  Requires-Dist: scipy
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: home-page
19
+ Dynamic: license-file
20
+ Dynamic: requires-dist
21
+ Dynamic: requires-python
22
+ Dynamic: summary
15
23
 
16
24
  # Numerical ODE Solver
17
25
 
18
- This project is a Python implementation for solving ordinary differential equations (ODEs) numerically. The script allows users to choose between two methods: Euler's Method and Runge-Kutta 4th Order Method (RK4), providing a visual representation of the solution.
26
+ This project is a Python implementation for solving ordinary differential equations (ODEs) numerically. The script allows users to choose between two methods: Euler's Method and Runge-Kutta 4th Order Method (RK4), providing a visual representation of the solution (optional). Note: Euler's Method is more inaccurate than RK4.
19
27
 
20
28
  ## Requirements
21
29
  Python version >= 3.8
@@ -28,27 +36,40 @@ pip install numODEsolver
28
36
  ```
29
37
  ## Example
30
38
  ```bash
31
- from numODEsolver import solver
39
+ import numODEsolver as ns
32
40
  import matplotlib.pyplot as plt #optional for plot
33
41
 
34
- solver = solver()
35
- f = solver.get_function("cos(x)")
36
- x,y = solver.solve_rk4(f,x0=0,y0=1,n=10000,bound=10.1)
37
- print(solver.get_value(x,y,val=10,dec=5)
42
+ solver = ns.Solver()
43
+ f = solver.get_function("y")
44
+ values = solver.rk4_1order(f,x0=0,y0=1,n=10000,bound=10.1)
45
+ n = solver.get_value(values,val=10,dec=5)
46
+ print(n)
47
+ plt.plot(results[:,0],results[:,1])
48
+ plt.show()
49
+ ```
50
+ ```bash
51
+ from numODEsolver import solver
52
+
53
+ solver = ns.Solver()
54
+ f = solver.get_function("y'+y") #y' = for 1st derivative. The ode would be y'' = y'+y
55
+ x,y,dy = solver.euler_2order(f,x0=0,y0=1,dy0=1,n=10000,bound=5)
56
+ n = solver.get_value(values,val=3,dec=2)
57
+ print(n)
38
58
  ```
39
59
 
40
60
  # Version History
41
61
 
42
62
  - 8.12.2024 - v0.1 -> only 1st order ODE's are solvable, more features coming soon
43
63
  - 15.12.2024 - v0.2 -> removed plot function
44
-
64
+ - 26.1.2025 - v0.3 -> included 2nd order methods, see more on GitHub
65
+ - 18.03.2025 - v2.0 -> more secure function handeling, more stable numerical methods.
45
66
 
46
67
  ---
47
68
  For more documentation take a look at the source code on my GitHub.
48
69
 
49
- You can modify the script to add more methods, adjust default parameters, or change visualization settings.
70
+ You can modify the script to add more methods, or change visualization settings.
50
71
 
51
- This project is open-source and free to use. Contributions and suggestions are welcome!
72
+ Contributions and suggestions are welcome!
52
73
 
53
74
  Lukas
54
75
 
@@ -0,0 +1,52 @@
1
+ # Numerical ODE Solver
2
+
3
+ This project is a Python implementation for solving ordinary differential equations (ODEs) numerically. The script allows users to choose between two methods: Euler's Method and Runge-Kutta 4th Order Method (RK4), providing a visual representation of the solution (optional). Note: Euler's Method is more inaccurate than RK4.
4
+
5
+ ## Requirements
6
+ Python version >= 3.8
7
+
8
+ Ensure the following Python libraries are installed:
9
+
10
+ Install it using `pip`:
11
+ ```bash
12
+ pip install numODEsolver
13
+ ```
14
+ ## Example
15
+ ```bash
16
+ import numODEsolver as ns
17
+ import matplotlib.pyplot as plt #optional for plot
18
+
19
+ solver = ns.Solver()
20
+ f = solver.get_function("y")
21
+ values = solver.rk4_1order(f,x0=0,y0=1,n=10000,bound=10.1)
22
+ n = solver.get_value(values,val=10,dec=5)
23
+ print(n)
24
+ plt.plot(results[:,0],results[:,1])
25
+ plt.show()
26
+ ```
27
+ ```bash
28
+ from numODEsolver import solver
29
+
30
+ solver = ns.Solver()
31
+ f = solver.get_function("y'+y") #y' = for 1st derivative. The ode would be y'' = y'+y
32
+ x,y,dy = solver.euler_2order(f,x0=0,y0=1,dy0=1,n=10000,bound=5)
33
+ n = solver.get_value(values,val=3,dec=2)
34
+ print(n)
35
+ ```
36
+
37
+ # Version History
38
+
39
+ - 8.12.2024 - v0.1 -> only 1st order ODE's are solvable, more features coming soon
40
+ - 15.12.2024 - v0.2 -> removed plot function
41
+ - 26.1.2025 - v0.3 -> included 2nd order methods, see more on GitHub
42
+ - 18.03.2025 - v2.0 -> more secure function handeling, more stable numerical methods.
43
+
44
+ ---
45
+ For more documentation take a look at the source code on my GitHub.
46
+
47
+ You can modify the script to add more methods, or change visualization settings.
48
+
49
+ Contributions and suggestions are welcome!
50
+
51
+ Lukas
52
+
@@ -0,0 +1,83 @@
1
+ from scipy.interpolate import interp1d
2
+ import numpy as np
3
+ from asteval import Interpreter
4
+
5
+
6
+ # get_function() -> Takes a function of x and y as an input. Make sure to use correct python syntax and put everything in curved brackets.
7
+ # --> Example: numODEsolver.get_function("x+y"), The diff.eq. would then be: y' = x+y and it will be numerically solved for y.
8
+ class Solver:
9
+ def __init__(self):
10
+ self.aeval = Interpreter()
11
+ def get_function(self, func):
12
+ func = func.lower()
13
+ if not "y'" in func:
14
+ f = self.aeval(f"lambda x,y: {func}")
15
+ return f
16
+ else:
17
+ func = func.replace("y'","dy")
18
+ f = self.aeval(f"lambda x,y,dy: {func}")
19
+ return f
20
+
21
+ def euler_2order(self,f,x0,y0,dy0,n,bound):
22
+ if n <= 0:
23
+ raise ValueError("n must be greater than zero.")
24
+ elif x0 > bound:
25
+ raise ValueError("initial condition must be < than the input bound!")
26
+ vals = np.zeros((n+1,3))
27
+ vals[0] = [x0,y0,dy0]
28
+ h = (bound-x0)/n
29
+ for i in range(n):
30
+ x,y,dy = vals[i]
31
+
32
+ dy_d = dy + h*f(x,y,dy)
33
+ y_d = y + h * dy_d
34
+ x_d = x + h
35
+ vals[i+1] = [x_d,y_d,dy_d]
36
+
37
+ return vals
38
+
39
+ def euler_1order(self,f,x0,y0,n,bound):
40
+ if n <= 0:
41
+ raise ValueError("n must be greater than zero.")
42
+ elif x0 > bound:
43
+ raise ValueError("initial condition must be < than the inpunt bound!")
44
+ vals = np.zeros((n+1, 2))
45
+ vals[0] = [x0,y0]
46
+ h = (bound-x0)/n
47
+ for i in range(n):
48
+ x,y = vals[i]
49
+ x_d = x0 + (i+1)*h
50
+ y_d = y + h*f(x,y)
51
+ vals[i+1] = [x_d,y_d]
52
+
53
+ return vals
54
+
55
+ def rk4_1order(self,f,x0,y0,n,bound):
56
+ if n <= 0:
57
+ raise ValueError("n must be greater than zero.")
58
+ elif x0 > bound:
59
+ raise ValueError("initial condition must be < than the inpunt bound!")
60
+ vals = np.zeros((n+1,2))
61
+ vals[0] = [x0,y0]
62
+ h = (bound-x0) / n
63
+ for i in range(n):
64
+ x,y = vals[i]
65
+
66
+ k1 = f(x,y)
67
+ k2 = f(x+h/2, y+h/2*k1)
68
+ k3 = f(x+h/2, y+h/2*k2)
69
+ k4 = f(x+h, y+h*k3)
70
+
71
+ x_d = x0 + (i+1)*h
72
+ y_d = y + h * (k1+2*k2+2*k3+k4)/6
73
+ vals[i+1] = [x_d,y_d]
74
+
75
+ return vals
76
+
77
+ # You can adjust the decimal places, note that rk4 is more accurate
78
+ def get_value(self,data,val,dec):
79
+ x_vals = data[:,0]
80
+ y_vals = data[:,1]
81
+ function = interp1d(x_vals,y_vals,kind="cubic")
82
+ num = np.round(function(val),dec)
83
+ return num
@@ -1,7 +1,7 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: numODEsolver
3
- Version: 0.5.2
4
- Summary: Tool that solves and plots ODE's numerically. Written in Python.
3
+ Version: 2.0.0
4
+ Summary: Tool that solves ODE's numerically. Written in Python.
5
5
  Home-page: https://github.com/lukasnf/Numerical-ODE-Solver
6
6
  Classifier: Programming Language :: Python :: 3
7
7
  Classifier: License :: OSI Approved :: MIT License
@@ -10,12 +10,20 @@ Requires-Python: >=3.8
10
10
  Description-Content-Type: text/markdown
11
11
  License-File: LICENSE
12
12
  Requires-Dist: numpy
13
- Requires-Dist: sympy
13
+ Requires-Dist: asteval
14
14
  Requires-Dist: scipy
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: home-page
19
+ Dynamic: license-file
20
+ Dynamic: requires-dist
21
+ Dynamic: requires-python
22
+ Dynamic: summary
15
23
 
16
24
  # Numerical ODE Solver
17
25
 
18
- This project is a Python implementation for solving ordinary differential equations (ODEs) numerically. The script allows users to choose between two methods: Euler's Method and Runge-Kutta 4th Order Method (RK4), providing a visual representation of the solution.
26
+ This project is a Python implementation for solving ordinary differential equations (ODEs) numerically. The script allows users to choose between two methods: Euler's Method and Runge-Kutta 4th Order Method (RK4), providing a visual representation of the solution (optional). Note: Euler's Method is more inaccurate than RK4.
19
27
 
20
28
  ## Requirements
21
29
  Python version >= 3.8
@@ -28,27 +36,40 @@ pip install numODEsolver
28
36
  ```
29
37
  ## Example
30
38
  ```bash
31
- from numODEsolver import solver
39
+ import numODEsolver as ns
32
40
  import matplotlib.pyplot as plt #optional for plot
33
41
 
34
- solver = solver()
35
- f = solver.get_function("cos(x)")
36
- x,y = solver.solve_rk4(f,x0=0,y0=1,n=10000,bound=10.1)
37
- print(solver.get_value(x,y,val=10,dec=5)
42
+ solver = ns.Solver()
43
+ f = solver.get_function("y")
44
+ values = solver.rk4_1order(f,x0=0,y0=1,n=10000,bound=10.1)
45
+ n = solver.get_value(values,val=10,dec=5)
46
+ print(n)
47
+ plt.plot(results[:,0],results[:,1])
48
+ plt.show()
49
+ ```
50
+ ```bash
51
+ from numODEsolver import solver
52
+
53
+ solver = ns.Solver()
54
+ f = solver.get_function("y'+y") #y' = for 1st derivative. The ode would be y'' = y'+y
55
+ x,y,dy = solver.euler_2order(f,x0=0,y0=1,dy0=1,n=10000,bound=5)
56
+ n = solver.get_value(values,val=3,dec=2)
57
+ print(n)
38
58
  ```
39
59
 
40
60
  # Version History
41
61
 
42
62
  - 8.12.2024 - v0.1 -> only 1st order ODE's are solvable, more features coming soon
43
63
  - 15.12.2024 - v0.2 -> removed plot function
44
-
64
+ - 26.1.2025 - v0.3 -> included 2nd order methods, see more on GitHub
65
+ - 18.03.2025 - v2.0 -> more secure function handeling, more stable numerical methods.
45
66
 
46
67
  ---
47
68
  For more documentation take a look at the source code on my GitHub.
48
69
 
49
- You can modify the script to add more methods, adjust default parameters, or change visualization settings.
70
+ You can modify the script to add more methods, or change visualization settings.
50
71
 
51
- This project is open-source and free to use. Contributions and suggestions are welcome!
72
+ Contributions and suggestions are welcome!
52
73
 
53
74
  Lukas
54
75
 
@@ -1,7 +1,6 @@
1
1
  LICENSE
2
2
  README.md
3
3
  setup.py
4
- numODEsolver/__init__.py
5
4
  numODEsolver/solver.py
6
5
  numODEsolver.egg-info/PKG-INFO
7
6
  numODEsolver.egg-info/SOURCES.txt
@@ -1,3 +1,3 @@
1
1
  numpy
2
- sympy
2
+ asteval
3
3
  scipy
@@ -8,13 +8,13 @@ classifiers = [
8
8
 
9
9
  setup(
10
10
  name="numODEsolver",
11
- version= "0.5.2",
12
- description= "Tool that solves and plots ODE's numerically. Written in Python.",
11
+ version= "2.0.0",
12
+ description= "Tool that solves ODE's numerically. Written in Python.",
13
13
  long_description=open("README.md").read(),
14
14
  long_description_content_type="text/markdown",
15
15
  url="https://github.com/lukasnf/Numerical-ODE-Solver",
16
16
  packages = ["numODEsolver"],
17
- install_requires=["numpy","sympy","scipy"],
17
+ install_requires=["numpy","asteval","scipy"],
18
18
  classifiers=classifiers,
19
19
  python_requires=">=3.8",
20
20
 
@@ -1,39 +0,0 @@
1
- # Numerical ODE Solver
2
-
3
- This project is a Python implementation for solving ordinary differential equations (ODEs) numerically. The script allows users to choose between two methods: Euler's Method and Runge-Kutta 4th Order Method (RK4), providing a visual representation of the solution.
4
-
5
- ## Requirements
6
- Python version >= 3.8
7
-
8
- Ensure the following Python libraries are installed:
9
-
10
- Install it using `pip`:
11
- ```bash
12
- pip install numODEsolver
13
- ```
14
- ## Example
15
- ```bash
16
- from numODEsolver import solver
17
- import matplotlib.pyplot as plt #optional for plot
18
-
19
- solver = solver()
20
- f = solver.get_function("cos(x)")
21
- x,y = solver.solve_rk4(f,x0=0,y0=1,n=10000,bound=10.1)
22
- print(solver.get_value(x,y,val=10,dec=5)
23
- ```
24
-
25
- # Version History
26
-
27
- - 8.12.2024 - v0.1 -> only 1st order ODE's are solvable, more features coming soon
28
- - 15.12.2024 - v0.2 -> removed plot function
29
-
30
-
31
- ---
32
- For more documentation take a look at the source code on my GitHub.
33
-
34
- You can modify the script to add more methods, adjust default parameters, or change visualization settings.
35
-
36
- This project is open-source and free to use. Contributions and suggestions are welcome!
37
-
38
- Lukas
39
-
@@ -1 +0,0 @@
1
- from .solver import solver
@@ -1,57 +0,0 @@
1
- import sympy as sp
2
- from scipy.interpolate import interp1d
3
- import numpy as np
4
-
5
- class solver:
6
- # get_function() -> Takes a function of x and y as an input. Make sure to use correct python syntax and put everything in curved brackets.
7
- # --> Example: numODEsolver.get_function("x+y"), The diff.eq. would then be: y' = x+y and it will be numerically solved for y.
8
- def get_function(self,func):
9
- x,y = sp.symbols("x y")
10
- func = sp.sympify(func)
11
- f = sp.lambdify((x,y), func, "numpy")
12
- return f
13
-
14
- # You can choose between 2 methods to solve the ODE numerically : euler and rk4. Those take the function f from before
15
- # as an input and 2 Initial conditions x0 and y0 as well as an x-axis bound. If n is a high number the result will be more accurate.
16
- # Both return arrays with the x,y values
17
- def solve_euler(self,f,x0,y0,n,bound):
18
- if n <= 0:
19
- raise ValueError("n must be greater than zero.")
20
- y = [y0]
21
- x = [x0]
22
- h = (bound-x0)/n
23
- for i in range(n):
24
- y_e = y[-1] + h * f(x[-1], y[-1])
25
- x_e = x[-1] + h
26
-
27
- x.append(x_e)
28
- y.append(y_e)
29
-
30
- return x, y
31
-
32
- def solve_rk4(self,f,x0,y0,n,bound):
33
- if n <= 0:
34
- raise ValueError("n must be greater than zero.")
35
- y = [y0]
36
- x = [x0]
37
- h = (bound-x0) / n
38
- for i in range(n):
39
- k1 = h * f(x[-1], y[-1])
40
- k2 = h * f(x[-1] + h / 2, y[-1] + k1 / 2)
41
- k3 = h * f(x[-1] + h / 2, y[-1] + k2 / 2)
42
- k4 = h * f(x[-1] + h, y[-1] + k3)
43
-
44
- y_r = y[-1] + (k1 + 2 * k2 + 2 * k3 + k4) / 6
45
- x_r = x[-1] + h
46
-
47
- x.append(x_r)
48
- y.append(y_r)
49
-
50
- return x, y
51
-
52
- # Allows you to get the y-value from a specific x-value
53
- # You can adjust the decimal places, note that rk4 is more accurate
54
- def get_value(self,x,y,val,dec):
55
- function = interp1d(x,y,kind="cubic")
56
- num = np.round(function(val),dec)
57
- return num
File without changes
File without changes