formulon-physics 0.1.3__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.
- formulon_physics-0.1.3/.gitignore +16 -0
- formulon_physics-0.1.3/LICENSE +21 -0
- formulon_physics-0.1.3/LICENSE.txt +9 -0
- formulon_physics-0.1.3/PKG-INFO +77 -0
- formulon_physics-0.1.3/README.md +49 -0
- formulon_physics-0.1.3/formulon/LICENSE +21 -0
- formulon_physics-0.1.3/formulon/README.md +1 -0
- formulon_physics-0.1.3/pyproject.toml +66 -0
- formulon_physics-0.1.3/src/formulon/__about__.py +4 -0
- formulon_physics-0.1.3/src/formulon/__init__.py +23 -0
- formulon_physics-0.1.3/src/formulon/classical_physics.py +842 -0
- formulon_physics-0.1.3/src/formulon/errorhandler.py +31 -0
- formulon_physics-0.1.3/tests/__init__.py +23 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SRIKALEESWARAR-S
|
|
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.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present SRIKALEESWARAR-S <srikaleeswarar675@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: formulon-physics
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: An open-source Python library offering classical physics formulas with automatic input validation and NumPy support.
|
|
5
|
+
Project-URL: Documentation, https://github.com/SRIKALEESWARAR-S/formulon#readme
|
|
6
|
+
Project-URL: Issues, https://github.com/SRIKALEESWARAR-S/formulon/issues
|
|
7
|
+
Project-URL: Source, https://github.com/SRIKALEESWARAR-S/formulon
|
|
8
|
+
Author-email: SRIKALEESWARAR-S <srikaleeswarar675@gmail.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: LICENSE.txt
|
|
12
|
+
Keywords: education,formulas,numpy,physics,science
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Education
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
24
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
25
|
+
Requires-Python: >=3.8
|
|
26
|
+
Requires-Dist: numpy>=1.20
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# formulon
|
|
31
|
+
|
|
32
|
+
[](https://pypi.org/project/formulon)
|
|
33
|
+
[](https://pypi.org/project/formulon)
|
|
34
|
+
[](https://spdx.org/licenses/MIT.html)
|
|
35
|
+
|
|
36
|
+
**formulon** is a lightweight, open-source Python library that provides commonly used
|
|
37
|
+
**classical physics formulas** with automatic input validation.This project is designed
|
|
38
|
+
and developed by SRI KALEESWARAR S, a Physics post graduate student from India.Its a
|
|
39
|
+
open source,free to use library.I thank my professors from Scott Christian college, special mention to
|
|
40
|
+
Kaniyam.com and open science labs
|
|
41
|
+
|
|
42
|
+
It is designed for **students, educators, and scientific Python users**, with support
|
|
43
|
+
for both scalar and NumPy-based vector calculations.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Table of Contents
|
|
48
|
+
|
|
49
|
+
- [Installation](#installation)
|
|
50
|
+
- [Usage](#usage)
|
|
51
|
+
- [Features](#features)
|
|
52
|
+
- [License](#license)
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
Install formulon from PyPI:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pip install formulon
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
formulon is distributed under the terms of the MIT License.
|
|
66
|
+
|
|
67
|
+
MIT License (Summary)
|
|
68
|
+
|
|
69
|
+
Free to use, modify, and distribute
|
|
70
|
+
|
|
71
|
+
Permitted for commercial and academic use
|
|
72
|
+
|
|
73
|
+
Provided without warranty
|
|
74
|
+
|
|
75
|
+
Full license text:
|
|
76
|
+
https://spdx.org/licenses/MIT.html
|
|
77
|
+
>>>>>>> 0350b6d (Welcome,Im born now)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
|
|
2
|
+
# formulon
|
|
3
|
+
|
|
4
|
+
[](https://pypi.org/project/formulon)
|
|
5
|
+
[](https://pypi.org/project/formulon)
|
|
6
|
+
[](https://spdx.org/licenses/MIT.html)
|
|
7
|
+
|
|
8
|
+
**formulon** is a lightweight, open-source Python library that provides commonly used
|
|
9
|
+
**classical physics formulas** with automatic input validation.This project is designed
|
|
10
|
+
and developed by SRI KALEESWARAR S, a Physics post graduate student from India.Its a
|
|
11
|
+
open source,free to use library.I thank my professors from Scott Christian college, special mention to
|
|
12
|
+
Kaniyam.com and open science labs
|
|
13
|
+
|
|
14
|
+
It is designed for **students, educators, and scientific Python users**, with support
|
|
15
|
+
for both scalar and NumPy-based vector calculations.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Table of Contents
|
|
20
|
+
|
|
21
|
+
- [Installation](#installation)
|
|
22
|
+
- [Usage](#usage)
|
|
23
|
+
- [Features](#features)
|
|
24
|
+
- [License](#license)
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
Install formulon from PyPI:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install formulon
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
formulon is distributed under the terms of the MIT License.
|
|
38
|
+
|
|
39
|
+
MIT License (Summary)
|
|
40
|
+
|
|
41
|
+
Free to use, modify, and distribute
|
|
42
|
+
|
|
43
|
+
Permitted for commercial and academic use
|
|
44
|
+
|
|
45
|
+
Provided without warranty
|
|
46
|
+
|
|
47
|
+
Full license text:
|
|
48
|
+
https://spdx.org/licenses/MIT.html
|
|
49
|
+
>>>>>>> 0350b6d (Welcome,Im born now)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SRIKALEESWARAR-S
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# formulon
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "formulon-physics"
|
|
7
|
+
version = "0.1.3"
|
|
8
|
+
description = "An open-source Python library offering classical physics formulas with automatic input validation and NumPy support."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
keywords = ["physics", "formulas", "science", "education", "numpy"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "SRIKALEESWARAR-S", email = "srikaleeswarar675@gmail.com" },
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Education",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.8",
|
|
23
|
+
"Programming Language :: Python :: 3.9",
|
|
24
|
+
"Programming Language :: Python :: 3.10",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
28
|
+
"Programming Language :: Python :: Implementation :: PyPy",
|
|
29
|
+
]
|
|
30
|
+
dependencies = [
|
|
31
|
+
"numpy>=1.20",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Documentation = "https://github.com/SRIKALEESWARAR-S/formulon#readme"
|
|
36
|
+
Issues = "https://github.com/SRIKALEESWARAR-S/formulon/issues"
|
|
37
|
+
Source = "https://github.com/SRIKALEESWARAR-S/formulon"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
[tool.hatch.envs.types]
|
|
41
|
+
extra-dependencies = [
|
|
42
|
+
"mypy>=1.0.0",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[tool.hatch.envs.types.scripts]
|
|
46
|
+
check = "mypy --install-types --non-interactive {args:src/formulon tests}"
|
|
47
|
+
|
|
48
|
+
[tool.coverage.run]
|
|
49
|
+
source_pkgs = ["formulon", "tests"]
|
|
50
|
+
branch = true
|
|
51
|
+
parallel = true
|
|
52
|
+
omit = [
|
|
53
|
+
"src/formulon/__about__.py",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
[tool.coverage.paths]
|
|
57
|
+
formulon = ["src/formulon", "*/formulon/src/formulon"]
|
|
58
|
+
tests = ["tests", "*/formulon/tests"]
|
|
59
|
+
|
|
60
|
+
[tool.coverage.report]
|
|
61
|
+
exclude_lines = [
|
|
62
|
+
"no cov",
|
|
63
|
+
"if __name__ == .__main__.:",
|
|
64
|
+
"if TYPE_CHECKING:",
|
|
65
|
+
]
|
|
66
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026-present SRIKALEESWARAR-S <srikaleeswarar675@gmail.com>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""
|
|
5
|
+
formulon
|
|
6
|
+
========
|
|
7
|
+
|
|
8
|
+
An open-source Python library providing classical physics formulas with
|
|
9
|
+
automatic input validation and NumPy support.
|
|
10
|
+
|
|
11
|
+
Designed for educational, scientific, and engineering use.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from .__about__ import __version__
|
|
15
|
+
|
|
16
|
+
# --- Public physics formula modules ---
|
|
17
|
+
from .classicalphysics import *
|
|
18
|
+
|
|
19
|
+
# --- Public API ---
|
|
20
|
+
__all__ = [
|
|
21
|
+
"__version__",
|
|
22
|
+
]
|
|
23
|
+
|
|
@@ -0,0 +1,842 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from .error_handler import validator
|
|
3
|
+
__all__ = [
|
|
4
|
+
|
|
5
|
+
"velocity",
|
|
6
|
+
"acceleration",
|
|
7
|
+
"velocity_at_const_accelaration",
|
|
8
|
+
"second_law_motion",
|
|
9
|
+
"final_velocity",
|
|
10
|
+
"kinematics_displacement",
|
|
11
|
+
"initial_velocity",
|
|
12
|
+
"average_acceleration",
|
|
13
|
+
"kinematics_time",
|
|
14
|
+
"average_velocity",
|
|
15
|
+
"average_speed",
|
|
16
|
+
"angular_frequency",
|
|
17
|
+
"alpha",
|
|
18
|
+
"linear_velocity",
|
|
19
|
+
"force",
|
|
20
|
+
"weight",
|
|
21
|
+
"momentum",
|
|
22
|
+
"force_momentum",
|
|
23
|
+
"arc_length",
|
|
24
|
+
"inertia"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
@validator("x","t")
|
|
33
|
+
def velocity(x,t):
|
|
34
|
+
"""
|
|
35
|
+
Compute velocity from position and time.
|
|
36
|
+
|
|
37
|
+
For scalar inputs, velocity is calculated as v = x / t.
|
|
38
|
+
For iterable inputs, velocity is computed using finite differences:
|
|
39
|
+
v = Δx / Δt.
|
|
40
|
+
|
|
41
|
+
Parameters
|
|
42
|
+
----------
|
|
43
|
+
x : float or array-like
|
|
44
|
+
Position value(s).
|
|
45
|
+
t : float or array-like
|
|
46
|
+
Time value(s).
|
|
47
|
+
|
|
48
|
+
Returns
|
|
49
|
+
-------
|
|
50
|
+
float or numpy.ndarray
|
|
51
|
+
Velocity value(s).
|
|
52
|
+
|
|
53
|
+
Raises
|
|
54
|
+
------
|
|
55
|
+
ValueError
|
|
56
|
+
If time or time differences are zero.
|
|
57
|
+
ValueError
|
|
58
|
+
If input arrays have mismatched lengths.
|
|
59
|
+
|
|
60
|
+
"""
|
|
61
|
+
#varibles with single value
|
|
62
|
+
if isinstance(x, (int, float)) and isinstance(t, (int, float)):
|
|
63
|
+
if t == 0:
|
|
64
|
+
raise ValueError("Time cannot be zero")
|
|
65
|
+
return x / t
|
|
66
|
+
|
|
67
|
+
# Case 2: iterables
|
|
68
|
+
x = np.array(x, dtype=float)
|
|
69
|
+
t = np.array(t, dtype=float)
|
|
70
|
+
|
|
71
|
+
if x.shape != t.shape:
|
|
72
|
+
raise ValueError("Position and time must have the same length")
|
|
73
|
+
|
|
74
|
+
dx = np.diff(x)
|
|
75
|
+
dt = np.diff(t)
|
|
76
|
+
|
|
77
|
+
if np.any(dt == 0):
|
|
78
|
+
raise ValueError("Time difference cannot be zero")
|
|
79
|
+
|
|
80
|
+
velocities = dx / dt
|
|
81
|
+
return velocities
|
|
82
|
+
@validator("v","t")
|
|
83
|
+
def acceleration(v,t):
|
|
84
|
+
"""
|
|
85
|
+
Compute acceleration from velocity and time.
|
|
86
|
+
|
|
87
|
+
For scalar inputs, acceleration is calculated as a = v / t.
|
|
88
|
+
For iterable inputs, acceleration is computed using finite differences:
|
|
89
|
+
a = Δv / Δt.
|
|
90
|
+
|
|
91
|
+
Parameters
|
|
92
|
+
----------
|
|
93
|
+
v : float or array-like
|
|
94
|
+
Velocity value(s).
|
|
95
|
+
t : float or array-like
|
|
96
|
+
Time value(s).
|
|
97
|
+
|
|
98
|
+
Returns
|
|
99
|
+
-------
|
|
100
|
+
float or numpy.ndarray
|
|
101
|
+
Acceleration value(s).
|
|
102
|
+
|
|
103
|
+
Raises
|
|
104
|
+
------
|
|
105
|
+
ValueError
|
|
106
|
+
If time or time differences are zero.
|
|
107
|
+
TypeError
|
|
108
|
+
If input arrays have mismatched lengths.
|
|
109
|
+
|
|
110
|
+
"""
|
|
111
|
+
if isinstance(v,(int,float)) and isinstance(t,(int,float)):
|
|
112
|
+
if t == 0:
|
|
113
|
+
raise ValueError("The Time values can not be zero")
|
|
114
|
+
return v/t
|
|
115
|
+
#case :2 iterables
|
|
116
|
+
v = np.array(v,dtype=float)
|
|
117
|
+
t = np.array(t,dtype=float)
|
|
118
|
+
if v.shape != t.shape:
|
|
119
|
+
raise TypeError("The arguments should have the same length")
|
|
120
|
+
dv = np.diff(v)
|
|
121
|
+
dt = np.diff(t)
|
|
122
|
+
if np.any(dt == 0):
|
|
123
|
+
raise ValueError("The time arguments should not be equal to zero")
|
|
124
|
+
accelarations = dv/dt
|
|
125
|
+
return accelarations
|
|
126
|
+
@validator("u","a","t")
|
|
127
|
+
def velocity_at_const_accelaration(u,a,t):
|
|
128
|
+
"""
|
|
129
|
+
Compute final velocity under constant acceleration.
|
|
130
|
+
|
|
131
|
+
Uses the kinematic equation:
|
|
132
|
+
v = u + at
|
|
133
|
+
|
|
134
|
+
Parameters
|
|
135
|
+
----------
|
|
136
|
+
u : float or array-like
|
|
137
|
+
Initial velocity.
|
|
138
|
+
a : float or array-like
|
|
139
|
+
Constant acceleration.
|
|
140
|
+
t : float or array-like
|
|
141
|
+
Time interval.
|
|
142
|
+
|
|
143
|
+
Returns
|
|
144
|
+
-------
|
|
145
|
+
float or numpy.ndarray
|
|
146
|
+
Final velocity.
|
|
147
|
+
|
|
148
|
+
Raises
|
|
149
|
+
------
|
|
150
|
+
ValueError
|
|
151
|
+
If any input value is zero or negative.
|
|
152
|
+
TypeError
|
|
153
|
+
If input arrays have mismatched lengths.
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
if isinstance (t,(int,float)) and isinstance(a,(int,float)) and isinstance(u,(int,float)):
|
|
157
|
+
if t <= 0:
|
|
158
|
+
raise ValueError("the values can not be zero at this point")
|
|
159
|
+
return u+(a*t)
|
|
160
|
+
u = np.array(u,dtype=float)
|
|
161
|
+
t = np.array(t,dtype=float)
|
|
162
|
+
a = np.array(a,dtype=float)
|
|
163
|
+
if u.shape != t.shape or u.shape != a.shape:
|
|
164
|
+
raise TypeError("All the files should have the same length")
|
|
165
|
+
if t <= 0:
|
|
166
|
+
raise v
|
|
167
|
+
velocity = u+(t*a)
|
|
168
|
+
return velocity
|
|
169
|
+
@validator("u","a","t")
|
|
170
|
+
def second_law_motion(u,a,t):
|
|
171
|
+
"""
|
|
172
|
+
Compute displacement using the second equation of motion.
|
|
173
|
+
|
|
174
|
+
Uses the formula:
|
|
175
|
+
s = ut + (1/2)at²
|
|
176
|
+
|
|
177
|
+
Parameters
|
|
178
|
+
----------
|
|
179
|
+
u : float or array-like
|
|
180
|
+
Initial velocity.
|
|
181
|
+
a : float or array-like
|
|
182
|
+
Acceleration.
|
|
183
|
+
t : float or array-like
|
|
184
|
+
Time.
|
|
185
|
+
|
|
186
|
+
Returns
|
|
187
|
+
-------
|
|
188
|
+
float or numpy.ndarray
|
|
189
|
+
Displacement.
|
|
190
|
+
|
|
191
|
+
Raises
|
|
192
|
+
------
|
|
193
|
+
ValueError
|
|
194
|
+
If any input value is zero or negative.
|
|
195
|
+
TypeError
|
|
196
|
+
If input arrays have mismatched lengths.
|
|
197
|
+
"""
|
|
198
|
+
if isinstance (t,(int,float)) and isinstance(a,(int,float)) and isinstance(u,(int,float)):
|
|
199
|
+
if t <= 0 or a <= 0 or u <= 0:
|
|
200
|
+
raise ValueError("the values can not be zero at this point")
|
|
201
|
+
return u*t + (0.5*a*t**2)
|
|
202
|
+
u = np.array(u,dtype=float)
|
|
203
|
+
t = np.array(t,dtype=float)
|
|
204
|
+
a = np.array(a,dtype=float)
|
|
205
|
+
if u.shape != t.shape or u.shape != a.shape:
|
|
206
|
+
raise TypeError("All the files should have the same length")
|
|
207
|
+
if any(u <= 0) or any(t <= 0) or any(a<= 0 ):
|
|
208
|
+
raise ValueError("The arguments should not be less than or equal to zero at any point")
|
|
209
|
+
motion = u*t + (0.5*a*t**2)
|
|
210
|
+
return motion
|
|
211
|
+
@validator("s","u","a")
|
|
212
|
+
def final_velocity(s,u,a):
|
|
213
|
+
"""
|
|
214
|
+
Compute final velocity using the third equation of motion.
|
|
215
|
+
|
|
216
|
+
Uses the formula:
|
|
217
|
+
v² = u² + 2as
|
|
218
|
+
|
|
219
|
+
Parameters
|
|
220
|
+
----------
|
|
221
|
+
s : float or array-like
|
|
222
|
+
Displacement.
|
|
223
|
+
u : float or array-like
|
|
224
|
+
Initial velocity.
|
|
225
|
+
a : float or array-like
|
|
226
|
+
Acceleration.
|
|
227
|
+
|
|
228
|
+
Returns
|
|
229
|
+
-------
|
|
230
|
+
float or numpy.ndarray
|
|
231
|
+
Final velocity (or velocity squared for arrays).
|
|
232
|
+
|
|
233
|
+
Raises
|
|
234
|
+
------
|
|
235
|
+
ValueError
|
|
236
|
+
If any input value is zero or negative.
|
|
237
|
+
TypeError
|
|
238
|
+
If input arrays have mismatched lengths.
|
|
239
|
+
|
|
240
|
+
"""
|
|
241
|
+
if isinstance(s,(int,float)) and isinstance(u,(int,float)) and isinstance(a,(int,float)):
|
|
242
|
+
if s <= 0 or u <= 0 or a <=0:
|
|
243
|
+
raise ValueError("The values can not be less than or equal to zero")
|
|
244
|
+
v = u**2 + 2*a*s
|
|
245
|
+
return np.sqrt(v)
|
|
246
|
+
s = np.array(s,dtype=float)
|
|
247
|
+
u = np.array(u,dtype=float)
|
|
248
|
+
a = np.array(a,dtype=float)
|
|
249
|
+
if s.shape != u.shape or u.shape != a.shape:
|
|
250
|
+
raise TypeError("The values should be in the same length")
|
|
251
|
+
final_velocitys = np.sqrt(u**2 + 2*a*s)
|
|
252
|
+
return final_velocitys
|
|
253
|
+
def kinematics_displacement(u,v,t):
|
|
254
|
+
"""
|
|
255
|
+
Compute displacement using average velocity.
|
|
256
|
+
|
|
257
|
+
Uses the formula:
|
|
258
|
+
s = (u + v)t / 2
|
|
259
|
+
|
|
260
|
+
Parameters
|
|
261
|
+
----------
|
|
262
|
+
u : float or array-like
|
|
263
|
+
Initial velocity.
|
|
264
|
+
v : float or array-like
|
|
265
|
+
Final velocity.
|
|
266
|
+
t : float or array-like
|
|
267
|
+
Time.
|
|
268
|
+
|
|
269
|
+
Returns
|
|
270
|
+
-------
|
|
271
|
+
float or numpy.ndarray
|
|
272
|
+
Displacement.
|
|
273
|
+
|
|
274
|
+
Raises
|
|
275
|
+
------
|
|
276
|
+
ValueError
|
|
277
|
+
If inputs contain zero or negative values.
|
|
278
|
+
TypeError
|
|
279
|
+
If input arrays have mismatched lengths.
|
|
280
|
+
"""
|
|
281
|
+
if isinstance(u,(int,float)) and isinstance(v,(int,float)) and isinstance(t,(int,float)):
|
|
282
|
+
if u < 0 or v <= 0 or t == 0:
|
|
283
|
+
raise ValueError("The input data values seems like having low or negative values")
|
|
284
|
+
return (u+v)*t/2
|
|
285
|
+
u = np.array(u,dtype=float)
|
|
286
|
+
v = np.array(v,dtype=float)
|
|
287
|
+
t = np.array(t,dtype=float)
|
|
288
|
+
if u.shape != v.shape or u.shape != t.shape:
|
|
289
|
+
raise TypeError("The arguments should have the same length")
|
|
290
|
+
if any(u <= 0) or any(v <= 0) or any(t <= 0):
|
|
291
|
+
raise ValueError("The values should not be less than or equal to zero")
|
|
292
|
+
displacement = (u+v)*t/2
|
|
293
|
+
return displacement
|
|
294
|
+
@validator("v","a","t")
|
|
295
|
+
def initial_velocity(v,a,t):
|
|
296
|
+
|
|
297
|
+
"""
|
|
298
|
+
Compute initial velocity from final velocity, acceleration, and time.
|
|
299
|
+
|
|
300
|
+
Uses the formula:
|
|
301
|
+
u = v − at
|
|
302
|
+
|
|
303
|
+
Parameters
|
|
304
|
+
----------
|
|
305
|
+
v : float or array-like
|
|
306
|
+
Final velocity.
|
|
307
|
+
a : float or array-like
|
|
308
|
+
Acceleration.
|
|
309
|
+
t : float or array-like
|
|
310
|
+
Time.
|
|
311
|
+
|
|
312
|
+
Returns
|
|
313
|
+
-------
|
|
314
|
+
float or numpy.ndarray
|
|
315
|
+
Initial velocity.
|
|
316
|
+
|
|
317
|
+
Raises
|
|
318
|
+
------
|
|
319
|
+
ValueError
|
|
320
|
+
If inputs contain zero or negative values.
|
|
321
|
+
TypeError
|
|
322
|
+
If input arrays have mismatched lengths.
|
|
323
|
+
"""
|
|
324
|
+
|
|
325
|
+
if isinstance(v,(int,float)) and isinstance(a,(int,float)) and isinstance(t,(int,float)):
|
|
326
|
+
if v <= 0 or t<= 0 or a <= 0:
|
|
327
|
+
raise ValueError("The arguments can not be zero or negative")
|
|
328
|
+
return v-a*t
|
|
329
|
+
v,a,t = np.array(v,dtype=float),np.array(a,dtype=float),np.array(t,dtype=float)
|
|
330
|
+
if v.shape != a.shape or v.shape != t.shape:
|
|
331
|
+
raise TypeError("The arguments should have the same length")
|
|
332
|
+
if any(v <= 0) or any(t <= 0) or any(a <= 0):
|
|
333
|
+
raise ValueError("The arguments should not be less than or equal to zero")
|
|
334
|
+
velocity = v-a*t
|
|
335
|
+
return velocity
|
|
336
|
+
def average_acceleration(v,u,t):
|
|
337
|
+
"""
|
|
338
|
+
Compute average acceleration.
|
|
339
|
+
|
|
340
|
+
Uses the formula:
|
|
341
|
+
a = (v − u) / t
|
|
342
|
+
|
|
343
|
+
Parameters
|
|
344
|
+
----------
|
|
345
|
+
v : float or array-like
|
|
346
|
+
Final velocity.
|
|
347
|
+
u : float or array-like
|
|
348
|
+
Initial velocity.
|
|
349
|
+
t : float or array-like
|
|
350
|
+
Time interval.
|
|
351
|
+
|
|
352
|
+
Returns
|
|
353
|
+
-------
|
|
354
|
+
float or numpy.ndarray
|
|
355
|
+
Average acceleration.
|
|
356
|
+
|
|
357
|
+
Raises
|
|
358
|
+
------
|
|
359
|
+
ValueError
|
|
360
|
+
If inputs contain zero or negative values.
|
|
361
|
+
TypeError
|
|
362
|
+
If input arrays have mismatched lengths.
|
|
363
|
+
"""
|
|
364
|
+
|
|
365
|
+
if isinstance(v,(int,float)) and isinstance(u,(int,float)) and isinstance(t,(int,float)):
|
|
366
|
+
if t <= 0 or v < 0 or u < 0:
|
|
367
|
+
raise ValueError("the arguments should not be zero or negative value")
|
|
368
|
+
return (v-u)/t
|
|
369
|
+
v,u,t = np.array(v,dtype=float),np.array(u,dtype=float),np.array(t,dtype=float)
|
|
370
|
+
if v.shape != u.shape or v.shape != t.shape:
|
|
371
|
+
raise TypeError("The arguments should have the same length")
|
|
372
|
+
if np.any(v <= 0) or np.any(t <= 0) or np.any(u <= 0):
|
|
373
|
+
raise ValueError("The arguments should not be less than or equal to zero")
|
|
374
|
+
acceleration = (v-u)/t
|
|
375
|
+
return acceleration
|
|
376
|
+
@validator("v","u","a")
|
|
377
|
+
def kinematics_time(v,u,a):
|
|
378
|
+
"""
|
|
379
|
+
Compute time using velocity and acceleration.
|
|
380
|
+
|
|
381
|
+
Uses the formula:
|
|
382
|
+
t = (v − u) / a
|
|
383
|
+
|
|
384
|
+
Parameters
|
|
385
|
+
----------
|
|
386
|
+
v : float or array-like
|
|
387
|
+
Final velocity.
|
|
388
|
+
u : float or array-like
|
|
389
|
+
Initial velocity.
|
|
390
|
+
a : float or array-like
|
|
391
|
+
Acceleration.
|
|
392
|
+
|
|
393
|
+
Returns
|
|
394
|
+
-------
|
|
395
|
+
float or numpy.ndarray
|
|
396
|
+
Time.
|
|
397
|
+
|
|
398
|
+
Raises
|
|
399
|
+
------
|
|
400
|
+
ValueError
|
|
401
|
+
If inputs contain negative values.
|
|
402
|
+
"""
|
|
403
|
+
|
|
404
|
+
if isinstance(v,(int,float)) and isinstance(u,(int,float) and isinstance(a,(int,float)):
|
|
405
|
+
if v < 0 or u < 0 or a < 0:
|
|
406
|
+
raise ValueError("Theres a negative value in the input, recheck ")
|
|
407
|
+
return (v-u)/a
|
|
408
|
+
if hasattr(v,"__iter__") and hasattr(u,"__iter__") and hasattr(a,"__iter__"):
|
|
409
|
+
v_list,u_list,a_list = v,u,a
|
|
410
|
+
if any(v_list <= 0) or any(u_list <= 0) or any(a_list <= 0):
|
|
411
|
+
raise ValueError("The values should not be zero")
|
|
412
|
+
return (v_list-u_list)/a_list
|
|
413
|
+
@validator("distance","time")
|
|
414
|
+
def average_velocity(distance,time):
|
|
415
|
+
"""
|
|
416
|
+
Compute average velocity.
|
|
417
|
+
|
|
418
|
+
Uses the formula:
|
|
419
|
+
v_avg = distance / time
|
|
420
|
+
|
|
421
|
+
Parameters
|
|
422
|
+
----------
|
|
423
|
+
distance : float or array-like
|
|
424
|
+
Total displacement.
|
|
425
|
+
time : float or array-like
|
|
426
|
+
Total time.
|
|
427
|
+
|
|
428
|
+
Returns
|
|
429
|
+
-------
|
|
430
|
+
float or numpy.ndarray
|
|
431
|
+
Average velocity.
|
|
432
|
+
|
|
433
|
+
Raises
|
|
434
|
+
------
|
|
435
|
+
ValueError
|
|
436
|
+
If inputs contain zero or negative values.
|
|
437
|
+
"""
|
|
438
|
+
|
|
439
|
+
if isinstance(time,(int,float)) and isinstance(distance,(int,float)):
|
|
440
|
+
if time <= 0 or distance <= 0:
|
|
441
|
+
raise ValueError("I think some values seems like zero or negative")
|
|
442
|
+
return distance/time
|
|
443
|
+
if hasattr(time,"__iter__") and hasattr(distance,"__iter__"):
|
|
444
|
+
t_list,d_list = time,distance
|
|
445
|
+
if any(t_list <= 0) or any(d_list <= 0):
|
|
446
|
+
raise ValueError("I think some values seems like zero or negative")
|
|
447
|
+
return d_list/t_list
|
|
448
|
+
|
|
449
|
+
@validator("distance","time")
|
|
450
|
+
def average_speed(distance,time):
|
|
451
|
+
"""
|
|
452
|
+
Compute average speed.
|
|
453
|
+
|
|
454
|
+
Uses the formula:
|
|
455
|
+
speed = distance / time
|
|
456
|
+
|
|
457
|
+
Parameters
|
|
458
|
+
----------
|
|
459
|
+
distance : float or array-like
|
|
460
|
+
Total distance travelled.
|
|
461
|
+
time : float or array-like
|
|
462
|
+
Time taken.
|
|
463
|
+
|
|
464
|
+
Returns
|
|
465
|
+
-------
|
|
466
|
+
float or numpy.ndarray
|
|
467
|
+
Average speed.
|
|
468
|
+
|
|
469
|
+
Raises
|
|
470
|
+
------
|
|
471
|
+
ValueError
|
|
472
|
+
If inputs contain zero or negative values.
|
|
473
|
+
"""
|
|
474
|
+
|
|
475
|
+
if isinstance(distance,(int,float)) and isinstance(time,(int,float)):
|
|
476
|
+
if distance <= 0 or time <= 0:
|
|
477
|
+
raise ValueError("I think youre entered a lower value")
|
|
478
|
+
return distance/time
|
|
479
|
+
if hasattr(distance,"__iter__") and hasattr(time,"__iter__"):
|
|
480
|
+
d_list,t_list = distance,time
|
|
481
|
+
if np.any(d_list <= 0) or np.any(t_list <= 0):
|
|
482
|
+
raise ValueError("I think you have entered a low value")
|
|
483
|
+
return d_list/t_list
|
|
484
|
+
@validator("theta","time")
|
|
485
|
+
def angular_frequency(theta,time):
|
|
486
|
+
"""
|
|
487
|
+
Compute angular frequency.
|
|
488
|
+
|
|
489
|
+
Uses the formula:
|
|
490
|
+
ω = θ / t
|
|
491
|
+
|
|
492
|
+
Parameters
|
|
493
|
+
----------
|
|
494
|
+
theta : float or array-like
|
|
495
|
+
Angular displacement in degrees.
|
|
496
|
+
time : float or array-like
|
|
497
|
+
Time interval.
|
|
498
|
+
|
|
499
|
+
Returns
|
|
500
|
+
-------
|
|
501
|
+
float or numpy.ndarray
|
|
502
|
+
Angular frequency.
|
|
503
|
+
|
|
504
|
+
Raises
|
|
505
|
+
------
|
|
506
|
+
ValueError
|
|
507
|
+
If theta is outside 0–360 degrees or time is negative.
|
|
508
|
+
"""
|
|
509
|
+
|
|
510
|
+
if isinstance(theta,(int,float)) and isinstance(time,(int,float)):
|
|
511
|
+
if theta > 360 or time < 0 or theta < 0:
|
|
512
|
+
raise ValueError("Theres a value error please check the values")
|
|
513
|
+
return theta/time
|
|
514
|
+
if hasattr(theta,"__iter__") and hasattr(time,"__iter__"):
|
|
515
|
+
t_list,theta_list = time,theta
|
|
516
|
+
for ti in t_list:
|
|
517
|
+
if ti < 0:
|
|
518
|
+
raise ValueError("Theres some low values. check")
|
|
519
|
+
for di in theta_list:
|
|
520
|
+
if di < 0 or di > 360:
|
|
521
|
+
raise ValueError("The theta values should be from 0 to 360")
|
|
522
|
+
return theta_list/t_list
|
|
523
|
+
@validator("omega","time")
|
|
524
|
+
def alpha(omega,time):
|
|
525
|
+
"""
|
|
526
|
+
Compute angular acceleration.
|
|
527
|
+
|
|
528
|
+
Uses the formula:
|
|
529
|
+
α = Δω / Δt
|
|
530
|
+
|
|
531
|
+
Parameters
|
|
532
|
+
----------
|
|
533
|
+
omega : float or array-like
|
|
534
|
+
Angular velocity.
|
|
535
|
+
time : float or array-like
|
|
536
|
+
Time.
|
|
537
|
+
|
|
538
|
+
Returns
|
|
539
|
+
-------
|
|
540
|
+
float or numpy.ndarray
|
|
541
|
+
Angular acceleration.
|
|
542
|
+
|
|
543
|
+
Raises
|
|
544
|
+
------
|
|
545
|
+
ValueError
|
|
546
|
+
If inputs contain zero or negative values.
|
|
547
|
+
"""
|
|
548
|
+
|
|
549
|
+
if isinstance(omega,(int,float)) and isinstance(time,(int,float)):
|
|
550
|
+
if omega <= 0 or time <= 0:
|
|
551
|
+
raise ValueError("The arguments should not be less than zero")
|
|
552
|
+
return omega/time
|
|
553
|
+
if hasattr(omega,"__iter__") and hasattr(time,"__iter__"):
|
|
554
|
+
omega_list,t_list = list(omega),list(time)
|
|
555
|
+
if len(omega_list) != len(t_list):
|
|
556
|
+
raise IndexError("Both of the arguments have the same length")
|
|
557
|
+
if np.any(omega_list <= 0) or np.any(t_list <= 0):
|
|
558
|
+
raise("Value ERROR due to low value arguments")
|
|
559
|
+
|
|
560
|
+
alphas = []
|
|
561
|
+
for i in range(len(omega_list) - 1):
|
|
562
|
+
da = omega_list[i + 1] - omega_list[i]
|
|
563
|
+
dt = t_list[i + 1] - t_list[i]
|
|
564
|
+
alphas.append(da/dt)
|
|
565
|
+
|
|
566
|
+
return alphas
|
|
567
|
+
@validator("v","w")
|
|
568
|
+
def linear_velocity(r,w):
|
|
569
|
+
"""
|
|
570
|
+
Compute linear velocity from angular velocity.
|
|
571
|
+
|
|
572
|
+
Uses the formula:
|
|
573
|
+
v = rω
|
|
574
|
+
|
|
575
|
+
Parameters
|
|
576
|
+
----------
|
|
577
|
+
r : float or array-like
|
|
578
|
+
Radius.
|
|
579
|
+
w : float or array-like
|
|
580
|
+
Angular velocity.
|
|
581
|
+
|
|
582
|
+
Returns
|
|
583
|
+
-------
|
|
584
|
+
float or numpy.ndarray
|
|
585
|
+
Linear velocity.
|
|
586
|
+
|
|
587
|
+
Raises
|
|
588
|
+
------
|
|
589
|
+
ValueError
|
|
590
|
+
If inputs contain zero or negative values.
|
|
591
|
+
"""
|
|
592
|
+
|
|
593
|
+
if isinstance(r,(int,float)) and isinstance(w,(int,float)):
|
|
594
|
+
if r <= 0 or w <= 0:
|
|
595
|
+
raise ValueError("The values should be greater than 0")
|
|
596
|
+
return r*w
|
|
597
|
+
if hasattr(r,"__iter__") and hasattr(w,"__iter__"):
|
|
598
|
+
r_list,w_list = list(r),list(w)
|
|
599
|
+
if np.any(r_list <= 0) or np.any(w_list <= 0):
|
|
600
|
+
raise ValueError("The values cant be less than or equal to zero")
|
|
601
|
+
l_velo = []
|
|
602
|
+
l_velo.append(r_list*w_list)#has to revise the code in the next version
|
|
603
|
+
return l_velo#runtime issues
|
|
604
|
+
@validator("m","a")
|
|
605
|
+
def force(m,a):
|
|
606
|
+
"""
|
|
607
|
+
Compute force using Newton’s second law.
|
|
608
|
+
|
|
609
|
+
Uses the formula:
|
|
610
|
+
F = ma
|
|
611
|
+
|
|
612
|
+
Parameters
|
|
613
|
+
----------
|
|
614
|
+
m : float or array-like
|
|
615
|
+
Mass.
|
|
616
|
+
a : float or array-like
|
|
617
|
+
Acceleration.
|
|
618
|
+
|
|
619
|
+
Returns
|
|
620
|
+
-------
|
|
621
|
+
float or numpy.ndarray
|
|
622
|
+
Force.
|
|
623
|
+
|
|
624
|
+
Raises
|
|
625
|
+
------
|
|
626
|
+
ValueError
|
|
627
|
+
If inputs contain negative values.
|
|
628
|
+
"""
|
|
629
|
+
|
|
630
|
+
if isinstance(m,(int,float)) and isinstance(a,(int,float)):
|
|
631
|
+
if m < 0 or a < 0:
|
|
632
|
+
raise ValueError("This values should be greater than 0")
|
|
633
|
+
return m*a
|
|
634
|
+
|
|
635
|
+
m_arr = np.array(m,dtype = float)
|
|
636
|
+
a_arr = np.array(a,dtype=float)
|
|
637
|
+
|
|
638
|
+
if m_arr.shape != a_arr.shape:
|
|
639
|
+
raise ValueError("Both must have same length")
|
|
640
|
+
if np.any(m_arr <= 0) or np.any(a_arr <= 0):
|
|
641
|
+
raise ValueError("None of the value should be zero or negative")
|
|
642
|
+
return m_arr*a_arr
|
|
643
|
+
validator("m","g")
|
|
644
|
+
def weight(m, g):
|
|
645
|
+
"""
|
|
646
|
+
Compute force using the formula:
|
|
647
|
+
momentum = m × g
|
|
648
|
+
|
|
649
|
+
Parameters
|
|
650
|
+
----------
|
|
651
|
+
m : float or list/array of float
|
|
652
|
+
Mass in kilograms (kg)
|
|
653
|
+
g : float or list/array of float
|
|
654
|
+
gravity
|
|
655
|
+
|
|
656
|
+
Returns
|
|
657
|
+
-------
|
|
658
|
+
float or numpy.ndarray
|
|
659
|
+
weight in (kg)
|
|
660
|
+
"""
|
|
661
|
+
|
|
662
|
+
# Scalar case
|
|
663
|
+
if isinstance(m, (int, float)) and isinstance(g, (int, float)):
|
|
664
|
+
if m <= 0 or g <= 0:
|
|
665
|
+
raise ValueError("Mass and acceleration must be positive values")
|
|
666
|
+
return m * g
|
|
667
|
+
|
|
668
|
+
# Array case
|
|
669
|
+
m_arr = np.array(m, dtype=float)
|
|
670
|
+
g_arr = np.array(g, dtype=float)
|
|
671
|
+
|
|
672
|
+
if m_arr.shape != g_arr.shape:
|
|
673
|
+
raise ValueError("Mass and acceleration must have the same length")
|
|
674
|
+
|
|
675
|
+
if np.any(m_arr <= 0) or np.any(g_arr <= 0):
|
|
676
|
+
raise ValueError("All values must be positive")
|
|
677
|
+
|
|
678
|
+
return m_arr * g_arr
|
|
679
|
+
@validator("m","v")
|
|
680
|
+
def momentum(m, v):
|
|
681
|
+
"""
|
|
682
|
+
Compute force using the formula:
|
|
683
|
+
momentum = m × v
|
|
684
|
+
|
|
685
|
+
Parameters
|
|
686
|
+
----------
|
|
687
|
+
m : float or list/array of float
|
|
688
|
+
Mass in kilograms (kg)
|
|
689
|
+
v : float or list/array of float
|
|
690
|
+
velocity (m/s)
|
|
691
|
+
|
|
692
|
+
Returns
|
|
693
|
+
-------
|
|
694
|
+
float or numpy.ndarray
|
|
695
|
+
momentum in (kg·m/s)
|
|
696
|
+
"""
|
|
697
|
+
|
|
698
|
+
# Scalar case
|
|
699
|
+
if isinstance(m, (int, float)) and isinstance(v, (int, float)):
|
|
700
|
+
if m <= 0 or v <= 0:
|
|
701
|
+
raise ValueError("Mass and velocity must be positive values")
|
|
702
|
+
return m * v
|
|
703
|
+
|
|
704
|
+
# Array case
|
|
705
|
+
m_arr = np.array(m, dtype=float)
|
|
706
|
+
v_arr = np.array(v, dtype=float)
|
|
707
|
+
|
|
708
|
+
if m_arr.shape != v_arr.shape:
|
|
709
|
+
raise ValueError("Mass and velocity must have the same length")
|
|
710
|
+
|
|
711
|
+
if np.any(m_arr <= 0) or np.any(v_arr <= 0):
|
|
712
|
+
raise ValueError("All values must be positive")
|
|
713
|
+
|
|
714
|
+
return m_arr * v_arr
|
|
715
|
+
@validator("p","t")
|
|
716
|
+
def force_momentum(p, t):
|
|
717
|
+
"""
|
|
718
|
+
Compute force from rate of change of momentum.
|
|
719
|
+
|
|
720
|
+
Uses the formula:
|
|
721
|
+
F = dp / dt
|
|
722
|
+
|
|
723
|
+
Parameters
|
|
724
|
+
----------
|
|
725
|
+
p : float or array-like
|
|
726
|
+
Momentum.
|
|
727
|
+
t : float or array-like
|
|
728
|
+
Time interval.
|
|
729
|
+
|
|
730
|
+
Returns
|
|
731
|
+
-------
|
|
732
|
+
float or numpy.ndarray
|
|
733
|
+
Force.
|
|
734
|
+
|
|
735
|
+
Raises
|
|
736
|
+
------
|
|
737
|
+
ValueError
|
|
738
|
+
If inputs contain zero or negative values.
|
|
739
|
+
"""
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
# Scalar case
|
|
743
|
+
if isinstance(p, (int, float)) and isinstance(t, (int, float)):
|
|
744
|
+
if p <= 0 or t <= 0:
|
|
745
|
+
raise ValueError("values must be greater than zero")
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
return p / t
|
|
749
|
+
|
|
750
|
+
# Iterable case
|
|
751
|
+
p_arr = np.array(p, dtype=float)
|
|
752
|
+
t_arr = np.array(t, dtype=float)
|
|
753
|
+
|
|
754
|
+
if p_arr.shape != t_arr.shape:
|
|
755
|
+
raise ValueError("momentum and time must have same length")
|
|
756
|
+
|
|
757
|
+
if np.any(p_arr <= 0) or np.any(t_arr <= 0):
|
|
758
|
+
raise ValueError("both should be greater than 0")
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
return p_arr / t_arr
|
|
764
|
+
@validator("r","theta")
|
|
765
|
+
def arc_length(r,theta):
|
|
766
|
+
"""
|
|
767
|
+
Compute arc length of a circle.
|
|
768
|
+
|
|
769
|
+
Uses the formula:
|
|
770
|
+
s = rθ
|
|
771
|
+
|
|
772
|
+
Parameters
|
|
773
|
+
----------
|
|
774
|
+
r : float or array-like
|
|
775
|
+
Radius.
|
|
776
|
+
theta : float or array-like
|
|
777
|
+
Angle in degrees.
|
|
778
|
+
|
|
779
|
+
Returns
|
|
780
|
+
-------
|
|
781
|
+
float or numpy.ndarray
|
|
782
|
+
Arc length.
|
|
783
|
+
|
|
784
|
+
Raises
|
|
785
|
+
------
|
|
786
|
+
ValueError
|
|
787
|
+
If theta is outside 0–360 degrees.
|
|
788
|
+
"""
|
|
789
|
+
|
|
790
|
+
if isinstance(r,(int,float)) and isinstance(theta,(int,float)):
|
|
791
|
+
if r <= 0 or theta < 0 or theta > 360:
|
|
792
|
+
raise ValueError("""The values should be greater than zero,
|
|
793
|
+
and theta should be in the range of 0 to 360""")
|
|
794
|
+
theta_rad = np.deg2rad(theta)
|
|
795
|
+
return r*theta_rad
|
|
796
|
+
r_arr = np.array(r,dtype = float)
|
|
797
|
+
theta_arr = np.array(theta,dtype = float)
|
|
798
|
+
if theta_arr.shape != r_arr.shape:
|
|
799
|
+
raise ValueError("The both of the arguments should have same length")
|
|
800
|
+
if np.any(theta_arr < 0) or np.any(theta_arr > 360):
|
|
801
|
+
raise ValueError("Theta value must be in between 0 to 360")
|
|
802
|
+
theta_rad = np.deg2rad(theta_arr)
|
|
803
|
+
return r_arr*theta_rad
|
|
804
|
+
@validator("m","r")
|
|
805
|
+
def inertia(m,r):
|
|
806
|
+
"""
|
|
807
|
+
Compute moment of inertia of a point mass.
|
|
808
|
+
|
|
809
|
+
Uses the formula:
|
|
810
|
+
I = mr²
|
|
811
|
+
|
|
812
|
+
Parameters
|
|
813
|
+
----------
|
|
814
|
+
m : float or array-like
|
|
815
|
+
Mass.
|
|
816
|
+
r : float or array-like
|
|
817
|
+
Radius.
|
|
818
|
+
|
|
819
|
+
Returns
|
|
820
|
+
-------
|
|
821
|
+
float or numpy.ndarray
|
|
822
|
+
Moment of inertia.
|
|
823
|
+
|
|
824
|
+
Raises
|
|
825
|
+
------
|
|
826
|
+
ValueError
|
|
827
|
+
If inputs contain zero or negative values.
|
|
828
|
+
"""
|
|
829
|
+
|
|
830
|
+
if isinstance (m,(int,float)) and isinstance(r,(int,float)):
|
|
831
|
+
if m <= 0 or r <= 0:
|
|
832
|
+
raise ValueError("The values should not be less than or equal to 0")
|
|
833
|
+
return m*(r**2)
|
|
834
|
+
m_arr = np.array(m,dtype = float)
|
|
835
|
+
r_arr = np.array(r,dtype = float)
|
|
836
|
+
if m_arr.shape != r_arr.shape:
|
|
837
|
+
raise TypeError("The arguments should be in same length")
|
|
838
|
+
if np.any(m_arr <= 0) or np.any(r_arr <= 0):
|
|
839
|
+
raise ValueError("The arguments should be greater than 0")
|
|
840
|
+
return m_arr*(r_arr**2)
|
|
841
|
+
|
|
842
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
def error_handler(x,name = "Value"):#finds
|
|
3
|
+
"""
|
|
4
|
+
"""
|
|
5
|
+
if x is None:
|
|
6
|
+
raise ValueError(f"The input {name} arguments should not be None")
|
|
7
|
+
|
|
8
|
+
if isinstance(x,str):# finds string input and empty string
|
|
9
|
+
if x == "":
|
|
10
|
+
raise ValueError("The values should not be a empty string")
|
|
11
|
+
|
|
12
|
+
raise TypeError(f"The {name} argument should not be string,it must be number")
|
|
13
|
+
if isinstance(x,tuple,list):
|
|
14
|
+
if len(x) == 0:
|
|
15
|
+
raise ValueError(f"The {name} list or tuple should not be zero")
|
|
16
|
+
x = np.array(x,dtype=float)
|
|
17
|
+
if isinstance(x,np.ndarray):
|
|
18
|
+
if x.size == 0:
|
|
19
|
+
raise ValueError(f"The {name} numpy array cant be zero")
|
|
20
|
+
if not np.all(np.isfinite(x)):
|
|
21
|
+
raise ValueError(f"The {name} values should be finite ")
|
|
22
|
+
return x
|
|
23
|
+
if isinstance(x, (int, float)):
|
|
24
|
+
if not np.isfinite(x):
|
|
25
|
+
raise ValueError(f"{name} contains NaN or Inf")
|
|
26
|
+
return x
|
|
27
|
+
|
|
28
|
+
# Anything else
|
|
29
|
+
raise TypeError(f"{name} has invalid type: {type(x)}")
|
|
30
|
+
|
|
31
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026-present SRIKALEESWARAR-S <srikaleeswarar675@gmail.com>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""
|
|
5
|
+
formulon
|
|
6
|
+
========
|
|
7
|
+
|
|
8
|
+
An open-source Python library providing classical physics formulas with
|
|
9
|
+
automatic input validation and NumPy support.
|
|
10
|
+
|
|
11
|
+
Designed for educational, scientific, and engineering use.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from .__about__ import __version__
|
|
15
|
+
|
|
16
|
+
# --- Public physics formula modules ---
|
|
17
|
+
from .classicalphysics import *
|
|
18
|
+
|
|
19
|
+
# --- Public API ---
|
|
20
|
+
__all__ = [
|
|
21
|
+
"__version__",
|
|
22
|
+
]
|
|
23
|
+
|