nbmath 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.
nbmath-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tc0512
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.
nbmath-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: nbmath
3
+ Version: 0.1.0
4
+ Summary: python零依赖数学库
5
+ Author-email: tc0512 <tancheng_0812@qq.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/tc0512/nbmath
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Dynamic: license-file
12
+
13
+ # nbmath
14
+
15
+ 一个实用的数学工具包,支持方程求解、几何计算、统计分析等功能。
16
+
17
+ ## 安装
18
+ ```bash
19
+ pip install nbmath
20
+ ```
nbmath-0.1.0/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # nbmath
2
+
3
+ 一个实用的数学工具包,支持方程求解、几何计算、统计分析等功能。
4
+
5
+ ## 安装
6
+ ```bash
7
+ pip install nbmath
8
+ ```
@@ -0,0 +1,16 @@
1
+ from . import const
2
+ from . import equation
3
+ from . import geometry
4
+ from . import plots
5
+ from . import stats
6
+ from . import utils
7
+
8
+ __all__ = [
9
+ 'const',
10
+ 'equation',
11
+ 'geometry',
12
+ 'plots',
13
+ 'stats',
14
+ 'utils'
15
+ ]
16
+ __version__ = "0.1.0"
@@ -0,0 +1,20 @@
1
+ def pi(): #π
2
+ return 3.1415926535897932
3
+ def e(): #e
4
+ return 2.7182818284590452
5
+ def tau(): #2π
6
+ return 6.2831853071795864
7
+ def phi(): #φ
8
+ return 1.6180339887498948
9
+ def G(): #万有引力常数(N·m^2/kg^2)
10
+ return 6.67430e-11
11
+ def c(): #光速(m/s)
12
+ return 299792458
13
+ def h(): #普朗克常数(J·s)
14
+ return 6.62607015e-34
15
+ def g(): #重力加速度(N/kg)
16
+ return 9.80665
17
+ def k(): #玻尔兹曼常数(J/K)
18
+ return 1.380649e-23
19
+ def NA(): #阿伏伽得罗常数(mol^-1)
20
+ return 6.02215076e23
@@ -0,0 +1,73 @@
1
+ from cmath import sqrt
2
+ I = 1j
3
+ def solve_linear_equation_in_one_unknown(a, b): #一元一次方程
4
+ return float('nan') if a==0 else [-b/a]
5
+ def solve_quadratic_equation(a, b, c): #一元二次方程
6
+ if a==0:
7
+ return float('nan')
8
+ x1 = (-b+sqrt(b**2-4*a*c))/(2*a)
9
+ x2 = (-b-sqrt(b**2-4*a*c))/(2*a)
10
+ return [x1, x2]
11
+ def solve_cubic_equation_in_one_unknown(a, b, c, d):#一元三次方程
12
+ if a==0:
13
+ return float('nan')
14
+ return [-(-3*c/a + b**2/a**2)/(3*(sqrt(-4*(-3*c/a + b**2/a**2)**3 + (27*d/a - 9*b*c/a**2 + 2*b**3/a**3)**2)/2 + 27*d/(2*a) - 9*b*c/(2*a**2) + b**3/a**3)**(1/3)) - (sqrt(-4*(-3*c/a + b**2/a**2)**3 + (27*d/a - 9*b*c/a**2 + 2*b**3/a**3)**2)/2 + 27*d/(2*a) - 9*b*c/(2*a**2) + b**3/a**3)**(1/3)/3 - b/(3*a), -(-3*c/a + b**2/a**2)/(3*(-1/2 - sqrt(3)*I/2)*(sqrt(-4*(-3*c/a + b**2/a**2)**3 + (27*d/a - 9*b*c/a**2 + 2*b**3/a**3)**2)/2 + 27*d/(2*a) - 9*b*c/(2*a**2) + b**3/a**3)**(1/3)) - (-1/2 - sqrt(3)*I/2)*(sqrt(-4*(-3*c/a + b**2/a**2)**3 + (27*d/a - 9*b*c/a**2 + 2*b**3/a**3)**2)/2 + 27*d/(2*a) - 9*b*c/(2*a**2) + b**3/a**3)**(1/3)/3 - b/(3*a), -(-3*c/a + b**2/a**2)/(3*(-1/2 + sqrt(3)*I/2)*(sqrt(-4*(-3*c/a + b**2/a**2)**3 + (27*d/a - 9*b*c/a**2 + 2*b**3/a**3)**2)/2 + 27*d/(2*a) - 9*b*c/(2*a**2) + b**3/a**3)**(1/3)) - (-1/2 + sqrt(3)*I/2)*(sqrt(-4*(-3*c/a + b**2/a**2)**3 + (27*d/a - 9*b*c/a**2 + 2*b**3/a**3)**2)/2 + 27*d/(2*a) - 9*b*c/(2*a**2) + b**3/a**3)**(1/3)/3 - b/(3*a)]
15
+ def solve_quartic_equation(a, b, c, d, e):
16
+ if a==0:
17
+ return float('nan')
18
+ x1 = -sqrt(-2*(-e/a + b*d/(4*a**2) - c**2/(12*a**2))/(3*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3)) + 2*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3) - 2*c/(3*a) + b**2/(4*a**2))/2 - sqrt((2*d/a - b*c/a**2 + b**3/(4*a**3))/sqrt(-2*(-e/a + b*d/(4*a**2) - c**2/(12*a**2))/(3*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3)) + 2*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3) - 2*c/(3*a) + b**2/(4*a**2)) + 2*(-e/a + b*d/(4*a**2) - c**2/(12*a**2))/(3*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3)) - 2*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3) - 4*c/(3*a) + b**2/(2*a**2))/2 - b/(4*a)
19
+ x2 = -sqrt(-2*(-e/a + b*d/(4*a**2) - c**2/(12*a**2))/(3*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3)) + 2*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3) - 2*c/(3*a) + b**2/(4*a**2))/2 + sqrt((2*d/a - b*c/a**2 + b**3/(4*a**3))/sqrt(-2*(-e/a + b*d/(4*a**2) - c**2/(12*a**2))/(3*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3)) + 2*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3) - 2*c/(3*a) + b**2/(4*a**2)) + 2*(-e/a + b*d/(4*a**2) - c**2/(12*a**2))/(3*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3)) - 2*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3) - 4*c/(3*a) + b**2/(2*a**2))/2 - b/(4*a)
20
+ x3 = sqrt(-2*(-e/a + b*d/(4*a**2) - c**2/(12*a**2))/(3*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3)) + 2*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3) - 2*c/(3*a) + b**2/(4*a**2))/2 - sqrt(-(2*d/a - b*c/a**2 + b**3/(4*a**3))/sqrt(-2*(-e/a + b*d/(4*a**2) - c**2/(12*a**2))/(3*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3)) + 2*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3) - 2*c/(3*a) + b**2/(4*a**2)) + 2*(-e/a + b*d/(4*a**2) - c**2/(12*a**2))/(3*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3)) - 2*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3) - 4*c/(3*a) + b**2/(2*a**2))/2 - b/(4*a)
21
+ x4 = sqrt(-2*(-e/a + b*d/(4*a**2) - c**2/(12*a**2))/(3*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3)) + 2*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3) - 2*c/(3*a) + b**2/(4*a**2))/2 + sqrt(-(2*d/a - b*c/a**2 + b**3/(4*a**3))/sqrt(-2*(-e/a + b*d/(4*a**2) - c**2/(12*a**2))/(3*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3)) + 2*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3) - 2*c/(3*a) + b**2/(4*a**2)) + 2*(-e/a + b*d/(4*a**2) - c**2/(12*a**2))/(3*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3)) - 2*((c/a - 3*b**2/(8*a**2))**3/216 - (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/6 + sqrt((-e/a + b*d/(4*a**2) - c**2/(12*a**2))**3/27 + (-(c/a - 3*b**2/(8*a**2))**3/108 + (c/a - 3*b**2/(8*a**2))*(e/a - b*d/(4*a**2) + b**2*c/(16*a**3) - 3*b**4/(256*a**4))/3 - (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/8)**2/4) + (d/a - b*c/(2*a**2) + b**3/(8*a**3))**2/16)**(1/3) - 4*c/(3*a) + b**2/(2*a**2))/2 - b/(4*a)
22
+ return [x1, x2, x3, x4]
23
+ def diff(fx: list): #求导
24
+ if len(fx)==0:
25
+ return float('nan')
26
+ elif len(fx)==1:
27
+ return 0
28
+ n = len(fx)
29
+ fx.reverse()
30
+ fpx = []
31
+ for i in range(n-1, 0, -1):
32
+ fpx.append(i*fx[i])
33
+ return fpx
34
+ def polyval(f: list, x): #代入求值
35
+ if len(f)==0:
36
+ return float('nan')
37
+ elif len(f)==1:
38
+ return f[0]
39
+ fx = 0
40
+ power = len(f)-1
41
+ for i in f:
42
+ fx+=i*x**power
43
+ power-=1
44
+ return fx
45
+ def newton_solver(fx: list, x0, depth):
46
+ x = x0
47
+ for i in range(depth):
48
+ fpx = diff(fx)
49
+ val_fpx = polyval(fpx, x)
50
+ if val_fpx==0:
51
+ raise ValueError("the derivative is zero so cannot iterate")
52
+ val_fx = polyval(fx, x)
53
+ x = x-val_fx/val_fpx
54
+ return x
55
+ def solve(*args): #统一求解函数接口
56
+ if len(args)==2: #双参数->一元一次
57
+ a, b = args
58
+ return solve_linear_equation_in_one_unknown(a, b)
59
+ elif len(args)==3: #三参数->一元二次/牛顿法
60
+ if isinstance(args[0], list): #第一参数为列表->牛顿法
61
+ fx, x0, depth = args
62
+ return newton_solver(fx, x0, depth)
63
+ else: #否则(第一参数为数字)->一元二次
64
+ a, b, c = args
65
+ return solve_quadratic_equation(a, b, c)
66
+ elif len(args)==4: #四参数->一元三次
67
+ a, b, c, d = args
68
+ return solve_cubic_equation_in_one_unknown(a, b, c, d)
69
+ elif len(args)==5: #五参数->一元四次
70
+ a, b, c, d, e = args
71
+ return solve_quartic_equation(a, b, c, d, e)
72
+ else: #都不是->不支持,报错
73
+ raise NotImplementedError("don't support this type of parameter")
@@ -0,0 +1,92 @@
1
+ import math
2
+ class Point: #点
3
+ def __init__(self, x, y):
4
+ self.x = x
5
+ self.y = y
6
+ def expression(self): #表达式
7
+ return f"({self.x}, {self.y})"
8
+ def dist(p1, p2): #两点距离
9
+ return math.sqrt((p2.x-p1.x)**2+(p2.y-p1.y)**2)
10
+ class Line: #线段
11
+ def __init__(self, p1, p2): #p1,p2均为Point几何对象
12
+ self.p1 = p1
13
+ self.p2 = p2
14
+ def length(self): #长度
15
+ return dist(self.p1, self.p2)
16
+ def midpoint(self): #中点
17
+ return Point((self.p1.x+self.p2.x)/2, (self.p1.y+self.p2.y)/2)
18
+ def expression(self): #表达式
19
+ k = (self.p2.y-self.p1.y)/(self.p2.x-self.p1.y)
20
+ b = self.p1.y-k*self.p1.x
21
+ x_min = min(self.p1.x, self.p2.x)
22
+ x_max = max(self.p1.x, self.p2.x)
23
+ if k!=0:
24
+ if b>0:
25
+ return f"y={k}x+{b}{{{x_min}≤x≤{x_max}}}"
26
+ elif b==0:
27
+ return f"y={k}x{{{x_min}≤x≤{x_max}}}"
28
+ elif b<0:
29
+ return f"y={k}x-{-b}{{{x_min}≤x≤{x_max}}}"
30
+ else:
31
+ return f"y={b}{{{x_min}≤x≤{x_max}}}"
32
+ class Circle: #圆
33
+ def __init__(self, O, r): #圆心是Point几何对象
34
+ self.O = O
35
+ self.r = r
36
+ def area(self): #面积
37
+ return math.pi*self.r**2
38
+ def circumference(self): #周长
39
+ return 2*math.pi*self.r
40
+ def diameter(self): #直径
41
+ return 2*self.r
42
+ def contains(self, point): #是否在圆内
43
+ return dist(self.O, point)<=self.r
44
+ def expression(self): #表达式
45
+ a = self.O.x
46
+ b = self.O.y
47
+ if a>0:
48
+ if b>0:
49
+ return f"(x-{a})^2+(y-{b})^2={self.r**2}"
50
+ elif b==0:
51
+ return f"(x-{a})^2+y^2={self.r**2}"
52
+ elif b<0:
53
+ return f"(x-{a})^2+(y+{-b})^2={self.r**2}"
54
+ elif a==0:
55
+ if b>0:
56
+ return f"x^2+(y-{b})^2={self.r**2}"
57
+ elif b==0:
58
+ return f"x^2+y^2={self.r**2}"
59
+ elif b<0:
60
+ return f"x^2+(y+{-b})^2={self.r**2}"
61
+ elif a<0:
62
+ if b>0:
63
+ return f"(x+{-a})^2+(y-{b})^2={self.r**2}"
64
+ elif b==0:
65
+ return f"(x+{-a})^2+y^2={self.r**2}"
66
+ elif b<0:
67
+ return f"(x+{-a})^2+(y+{-b})^2={self.r**2}"
68
+ class Polygon:
69
+ def __init__(self, points): #points是Point几何对象
70
+ self.points = points
71
+ def area(self): #面积
72
+ n = len(self.points)
73
+ if n<3:
74
+ return 0
75
+ s = 0
76
+ for i in range(n):
77
+ x1, y1 = self.points[i].x, self.points[i].y
78
+ x2, y2 = self.points[(i+1)%n].x, self.points[(i+1)%n].y
79
+ s+=x1*y2-x2*y1
80
+ return abs(s)/2
81
+ def circumference(self):
82
+ n = len(self.points)
83
+ if n<2:
84
+ return 0
85
+ elif n==2:
86
+ return dist(self.points[0], self.points[1])
87
+ C = 0
88
+ for i in range(n):
89
+ p1 = self.points[i]
90
+ p2 = self.points[(i+1)%n]
91
+ C+=dist(p1, p2)
92
+ return C
@@ -0,0 +1,72 @@
1
+ import turtle as t
2
+ _length = _height = None
3
+ _llx = _lly = _urx = _ury = None
4
+ def window(length, height): #窗口(t.setup)
5
+ global _length, _height
6
+ _length, _height = length, height
7
+ t.setup(length, height)
8
+ t.hideturtle()
9
+ t.speed(0)
10
+ t.tracer(0)
11
+ t.penup()
12
+ def setax(llx, lly, urx, ury): #设置坐标系范围(t.setworldcoordinates)
13
+ global _llx, _lly, _urx , _ury
14
+ _llx, _lly, _urx , _ury = llx, lly, urx, ury
15
+ t.setworldcoordinates(llx, lly, urx, ury)
16
+ def drawaxhline(): #绘制坐标轴
17
+ global _length, _height, _llx, _lly, _urx , _ury
18
+ if None in (_length, _height):
19
+ raise ValueError("please use 'window' first to create a window")
20
+ elif None in (_llx, _lly, _urx , _ury):
21
+ x_min, x_max = -_length/2, _length/2
22
+ y_min, y_max = -_height/2, _height/2
23
+ else:
24
+ x_min, x_max = _llx, _urx
25
+ y_min, y_max = _lly, _ury
26
+ t.penup()
27
+ t.goto(x_min, 0)
28
+ t.pendown()
29
+ t.goto(x_max, 0)
30
+ t.penup()
31
+ t.goto(0, y_min)
32
+ t.pendown()
33
+ t.goto(0, y_max)
34
+ t.penup()
35
+ t.update()
36
+ def point(x, y, color: str, size: int, label: str): #描点
37
+ t.penup()
38
+ t.goto(x, y)
39
+ t.pencolor(color)
40
+ t.dot(size)
41
+ t.write(label)
42
+ t.penup()
43
+ t.update()
44
+ def line(x: list, y: list, color: str, linewidth: int): #绘制线段
45
+ t.penup()
46
+ t.goto(x[0], y[0])
47
+ t.pendown()
48
+ t.pencolor(color)
49
+ t.pensize(linewidth)
50
+ t.goto(x[1], y[1])
51
+ t.pensize(1)
52
+ t.update()
53
+ def plot_function(f, x_min, x_max, color: str, linewidth: int, steps: int): #函数图像y=f(x)
54
+ t.penup()
55
+ dx = (x_max-x_min)/steps
56
+ for i in range(steps+1):
57
+ x = x_min+i*dx
58
+ y = f(x)
59
+ t.goto(x, y)
60
+ if i==0:
61
+ t.pendown()
62
+ t.pencolor(color)
63
+ t.pensize(linewidth)
64
+ t.penup()
65
+ t.update()
66
+ def scatter(points: list, color: str): #散点图
67
+ t.penup()
68
+ t.pencolor(color)
69
+ for i in points:
70
+ t.goto(i)
71
+ t.dot(5)
72
+ t.update()
@@ -0,0 +1,50 @@
1
+ import statistics
2
+ import math
3
+ def mean(data: list):
4
+ if len(data)==0:
5
+ raise statistics.StatisticsError("mean requires at least one data point")
6
+ return sum(data)/len(data)
7
+ def SS(data: list):
8
+ if len(data)==0:
9
+ raise statistics.StatisticsError("sum of deviation square requires at least one data point")
10
+ average = mean(data)
11
+ ss = 0
12
+ for i in data:
13
+ ss+=(i-average)**2
14
+ return ss
15
+ def var(data: list):
16
+ if len(data)==0:
17
+ raise statistics.StatisticsError("variance requires at least one data point")
18
+ elif len(data)==1:
19
+ return 0
20
+ return SS(data)/len(data)
21
+ def std(data: list):
22
+ if len(data)==0:
23
+ raise statistics.StatisticsError("standard deviation requires at least one data point")
24
+ elif len(data)==1:
25
+ return 0
26
+ return math.sqrt(var(data))
27
+ def data_range(data: list):
28
+ if len(data)<2:
29
+ raise statistics.StatisticsError("range requires at least two data points")
30
+ return max(data)-min(data)
31
+ def percentile(data: list, p: int):
32
+ if len(data)==0:
33
+ raise statistics.StatisticsError("percentile requires at least one data point")
34
+ elif len(data)==1:
35
+ return data[0]
36
+ data.sort()
37
+ pos = len(data)*p/100
38
+ if int(pos)==pos:
39
+ index1 = int(pos-1)
40
+ index2 = int(pos)
41
+ return (data[index1]+data[index2])/2
42
+ else:
43
+ index = int(pos)
44
+ return data[index]
45
+ def mode(data):
46
+ freq = {}
47
+ for x in data:
48
+ freq[x] = freq.get(x, 0) + 1
49
+ max_freq = max(freq.values())
50
+ return [k for k, v in freq.items() if v == max_freq]
@@ -0,0 +1,68 @@
1
+ import time
2
+ def diff(fx: list): #求导
3
+ if len(fx)==0:
4
+ return float('nan')
5
+ elif len(fx)==1:
6
+ return 0
7
+ n = len(fx)
8
+ fx.reverse()
9
+ fpx = []
10
+ for i in range(n-1, 0, -1):
11
+ fpx.append(i*fx[i])
12
+ return fpx
13
+ def polyval(f: list, x): #代入求值
14
+ if len(f)==0:
15
+ return float('nan')
16
+ elif len(f)==1:
17
+ return f[0]
18
+ fx = 0
19
+ power = len(f)-1
20
+ for i in f:
21
+ fx+=i*x**power
22
+ power-=1
23
+ return fx
24
+ def linspace(start, end, steps): #np.linspace的纯python实现
25
+ if steps==0:
26
+ return []
27
+ elif steps==1:
28
+ return [start]
29
+ dx = (end-start)/steps
30
+ result = []
31
+ for i in range(steps+1):
32
+ x = start+i*dx
33
+ result.append(x)
34
+ return result
35
+ def timer(func): #计时器
36
+ def wrapper(*args, **kwargs):
37
+ start = time.time()
38
+ result = func(*args, **kwargs)
39
+ print(f"{func.__name__} 耗时: {time.time()-start:.4f}秒")
40
+ return result
41
+ return wrapper
42
+ def gcd(a: int, b: int): #最大公约数
43
+ while b:
44
+ a, b = b, a%b
45
+ return abs(a)
46
+ def lcm(a: int, b: int): #最小公倍数
47
+ return a*b/gcd(a, b)
48
+ def floor(x): #向下取整
49
+ if x>=0:
50
+ return int(x)
51
+ return int(x)-1
52
+ def trunc(x): #截断取整
53
+ return int(x)
54
+ def frac(x): #小数部分
55
+ if x>=0:
56
+ return x-int(x)
57
+ return x-int(x)+1
58
+ def fac(x): #阶乘
59
+ if x>0 and int(x)==x:
60
+ result = 1
61
+ for i in range(1, x+1):
62
+ result*=i
63
+ return result
64
+ elif x==0:
65
+ return 1
66
+ elif x<0 and int(x)==x:
67
+ return float('nan')
68
+ return math.gamma(x+1)
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: nbmath
3
+ Version: 0.1.0
4
+ Summary: python零依赖数学库
5
+ Author-email: tc0512 <tancheng_0812@qq.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/tc0512/nbmath
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Dynamic: license-file
12
+
13
+ # nbmath
14
+
15
+ 一个实用的数学工具包,支持方程求解、几何计算、统计分析等功能。
16
+
17
+ ## 安装
18
+ ```bash
19
+ pip install nbmath
20
+ ```
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ nbmath/__init__.py
5
+ nbmath/const.py
6
+ nbmath/equation.py
7
+ nbmath/geometry.py
8
+ nbmath/plots.py
9
+ nbmath/stats.py
10
+ nbmath/utils.py
11
+ nbmath.egg-info/PKG-INFO
12
+ nbmath.egg-info/SOURCES.txt
13
+ nbmath.egg-info/dependency_links.txt
14
+ nbmath.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ nbmath
@@ -0,0 +1,18 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "nbmath"
7
+ version = "0.1.0"
8
+ description = "python零依赖数学库"
9
+ authors = [
10
+ {name = "tc0512", email = "tancheng_0812@qq.com"}
11
+ ]
12
+ license = {text = "MIT"}
13
+ readme = "README.md"
14
+ requires-python = ">=3.8"
15
+ dependencies = []
16
+
17
+ [project.urls]
18
+ Homepage = "https://github.com/tc0512/nbmath"
nbmath-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+