nbmath 0.2.3__tar.gz → 1.0.4__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.2.3 → nbmath-1.0.4}/PKG-INFO +30 -3
- {nbmath-0.2.3 → nbmath-1.0.4}/README.md +29 -2
- {nbmath-0.2.3 → nbmath-1.0.4}/nbmath/__init__.py +3 -3
- {nbmath-0.2.3 → nbmath-1.0.4}/nbmath/plots/core.py +23 -5
- nbmath-1.0.4/nbmath/plots/examples/__init__.py +7 -0
- nbmath-1.0.4/nbmath/plots/examples/cantor_stair.py +20 -0
- {nbmath-0.2.3 → nbmath-1.0.4}/nbmath/plots/examples/heart.py +1 -1
- {nbmath-0.2.3 → nbmath-1.0.4}/nbmath/plots/examples/lissajous.py +1 -1
- nbmath-1.0.4/nbmath/plots/examples/mandelbrot.py +38 -0
- {nbmath-0.2.3 → nbmath-1.0.4}/nbmath/plots/examples/sin.py +1 -1
- {nbmath-0.2.3 → nbmath-1.0.4}/nbmath/utils.py +4 -0
- {nbmath-0.2.3 → nbmath-1.0.4}/nbmath.egg-info/PKG-INFO +30 -3
- {nbmath-0.2.3 → nbmath-1.0.4}/nbmath.egg-info/SOURCES.txt +3 -1
- {nbmath-0.2.3 → nbmath-1.0.4}/pyproject.toml +1 -1
- nbmath-0.2.3/nbmath/plots/examples/__init__.py +0 -5
- {nbmath-0.2.3 → nbmath-1.0.4}/LICENSE +0 -0
- {nbmath-0.2.3 → nbmath-1.0.4}/nbmath/const.py +0 -0
- {nbmath-0.2.3 → nbmath-1.0.4}/nbmath/equation.py +0 -0
- /nbmath-0.2.3/nbmath/geometry.py → /nbmath-1.0.4/nbmath/geo.py +0 -0
- {nbmath-0.2.3 → nbmath-1.0.4}/nbmath/optimize.py +0 -0
- {nbmath-0.2.3 → nbmath-1.0.4}/nbmath/plots/__init__.py +0 -0
- {nbmath-0.2.3 → nbmath-1.0.4}/nbmath/stats.py +0 -0
- {nbmath-0.2.3 → nbmath-1.0.4}/nbmath.egg-info/dependency_links.txt +0 -0
- {nbmath-0.2.3 → nbmath-1.0.4}/nbmath.egg-info/top_level.txt +0 -0
- {nbmath-0.2.3 → nbmath-1.0.4}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nbmath
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.4
|
|
4
4
|
Summary: python零依赖数学库
|
|
5
5
|
Author-email: tc0512 <tancheng_0812@qq.com>
|
|
6
6
|
License: MIT
|
|
@@ -16,7 +16,7 @@ Dynamic: license-file
|
|
|
16
16
|
|
|
17
17
|
## 安装
|
|
18
18
|
```bash
|
|
19
|
-
pip install https://ghproxy.net/https://github.com/tc0512/nbmath/releases/download/
|
|
19
|
+
pip install https://ghproxy.net/https://github.com/tc0512/nbmath/releases/download/v1.0.4/nbmath-1.0.4-py3-none-any.whl
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## 快速开始
|
|
@@ -24,6 +24,8 @@ pip install https://ghproxy.net/https://github.com/tc0512/nbmath/releases/downlo
|
|
|
24
24
|
from nbmath.equation import solve
|
|
25
25
|
from nbmath.const import pi
|
|
26
26
|
from nbmath.optimize import newton
|
|
27
|
+
from nbmath.utils import is_odd
|
|
28
|
+
import os
|
|
27
29
|
|
|
28
30
|
#解方程
|
|
29
31
|
print(solve(1, -3, 2)) #[(2+0j), (1+0j)]
|
|
@@ -35,6 +37,12 @@ print(pi()) #3.141592653589793
|
|
|
35
37
|
TOL = 1e-6
|
|
36
38
|
MAX_ITER = 100
|
|
37
39
|
print(newton(lambda x: x**2+6*x+9, 1.5, TOL, MAX_ITER)) #x接近-3,y接近0(有浮点误差)
|
|
40
|
+
|
|
41
|
+
#绘制康托尔阶梯
|
|
42
|
+
os.system("python -m nbmath.plots.examples.cantor_stair")
|
|
43
|
+
|
|
44
|
+
#判断是否为奇数
|
|
45
|
+
print(is_odd(99999)) #True
|
|
38
46
|
```
|
|
39
47
|
|
|
40
48
|
## 模块介绍
|
|
@@ -46,7 +54,7 @@ print(newton(lambda x: x**2+6*x+9, 1.5, TOL, MAX_ITER)) #x接近-3,y接近0(有
|
|
|
46
54
|
- 牛顿迭代法解高次方程
|
|
47
55
|
- 不等式
|
|
48
56
|
- 统一接口`solve`
|
|
49
|
-
### 几何模块`nbmath.
|
|
57
|
+
### 几何模块`nbmath.geo`
|
|
50
58
|
- 点`Point`
|
|
51
59
|
- 线段`Line`
|
|
52
60
|
- 圆`Circle`
|
|
@@ -61,18 +69,26 @@ print(newton(lambda x: x**2+6*x+9, 1.5, TOL, MAX_ITER)) #x接近-3,y接近0(有
|
|
|
61
69
|
- `np.linspace`纯python实现
|
|
62
70
|
- `polyval`多项式代入求值
|
|
63
71
|
- `timer`计时器
|
|
72
|
+
- `is_even` `is_odd`奇偶数判断
|
|
64
73
|
### 优化算法模块`nbmath.optimize`
|
|
65
74
|
- `brute`咆哮算法
|
|
66
75
|
- `golden_section`黄金分割法
|
|
67
76
|
- `newton`牛顿法
|
|
68
77
|
- `gradient_descent`梯度下降
|
|
69
78
|
- `simulated_annealing`模拟退火
|
|
79
|
+
### 绘图模块`nbmath.plots`
|
|
80
|
+
- `point`描点 `scatter`散点图
|
|
81
|
+
- `line`线段 `fun`绘制函数F(x)
|
|
82
|
+
- `rect`矩形
|
|
83
|
+
- `mandelbrot` `heart`等共5个示例图案
|
|
70
84
|
|
|
71
85
|
## 示例代码
|
|
72
86
|
```python
|
|
73
87
|
from nbmath.equation import solve
|
|
74
88
|
from nbmath.stats import mode
|
|
75
89
|
from nbmath.optimize import simulated_annealing
|
|
90
|
+
from nbmath import plots as plt
|
|
91
|
+
import math
|
|
76
92
|
|
|
77
93
|
#求解x^4-10x^2+9=0
|
|
78
94
|
roots = solve(1, 0, -10, 0, 9)
|
|
@@ -89,7 +105,18 @@ COOLING = 0.95
|
|
|
89
105
|
STEPS = 1000
|
|
90
106
|
TOL = 1e-6
|
|
91
107
|
print(simulated_annealing(F, -5, 5, TEMP, COOLING, STEPS, TOL)) #{'x': -1.581998612252256, 'fun': -2.249992603725974}
|
|
108
|
+
|
|
109
|
+
#绘制y=cos(x)
|
|
110
|
+
plt.window(800, 600)
|
|
111
|
+
plt.setax(-2*math.pi, -1.5*math.pi, 2*math.pi, 1.5*math.pi)
|
|
112
|
+
plt.drawaxhline()
|
|
113
|
+
plt.plot_function(lambda x: math.sin(x), -2*math.pi, 2*math.pi)
|
|
114
|
+
plt.rect(1, 1, 1.5, 0.5, "red") #绘制一个左下角(1,1),长1.5,宽0.5的红色矩形
|
|
115
|
+
plt.keep_window()
|
|
92
116
|
```
|
|
93
117
|
|
|
94
118
|
## 许可证
|
|
95
119
|
MIT
|
|
120
|
+
|
|
121
|
+
**警告**
|
|
122
|
+
nbmath-1.0.0有bug,请下载nbmath-1.0.3
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## 安装
|
|
6
6
|
```bash
|
|
7
|
-
pip install https://ghproxy.net/https://github.com/tc0512/nbmath/releases/download/
|
|
7
|
+
pip install https://ghproxy.net/https://github.com/tc0512/nbmath/releases/download/v1.0.4/nbmath-1.0.4-py3-none-any.whl
|
|
8
8
|
```
|
|
9
9
|
|
|
10
10
|
## 快速开始
|
|
@@ -12,6 +12,8 @@ pip install https://ghproxy.net/https://github.com/tc0512/nbmath/releases/downlo
|
|
|
12
12
|
from nbmath.equation import solve
|
|
13
13
|
from nbmath.const import pi
|
|
14
14
|
from nbmath.optimize import newton
|
|
15
|
+
from nbmath.utils import is_odd
|
|
16
|
+
import os
|
|
15
17
|
|
|
16
18
|
#解方程
|
|
17
19
|
print(solve(1, -3, 2)) #[(2+0j), (1+0j)]
|
|
@@ -23,6 +25,12 @@ print(pi()) #3.141592653589793
|
|
|
23
25
|
TOL = 1e-6
|
|
24
26
|
MAX_ITER = 100
|
|
25
27
|
print(newton(lambda x: x**2+6*x+9, 1.5, TOL, MAX_ITER)) #x接近-3,y接近0(有浮点误差)
|
|
28
|
+
|
|
29
|
+
#绘制康托尔阶梯
|
|
30
|
+
os.system("python -m nbmath.plots.examples.cantor_stair")
|
|
31
|
+
|
|
32
|
+
#判断是否为奇数
|
|
33
|
+
print(is_odd(99999)) #True
|
|
26
34
|
```
|
|
27
35
|
|
|
28
36
|
## 模块介绍
|
|
@@ -34,7 +42,7 @@ print(newton(lambda x: x**2+6*x+9, 1.5, TOL, MAX_ITER)) #x接近-3,y接近0(有
|
|
|
34
42
|
- 牛顿迭代法解高次方程
|
|
35
43
|
- 不等式
|
|
36
44
|
- 统一接口`solve`
|
|
37
|
-
### 几何模块`nbmath.
|
|
45
|
+
### 几何模块`nbmath.geo`
|
|
38
46
|
- 点`Point`
|
|
39
47
|
- 线段`Line`
|
|
40
48
|
- 圆`Circle`
|
|
@@ -49,18 +57,26 @@ print(newton(lambda x: x**2+6*x+9, 1.5, TOL, MAX_ITER)) #x接近-3,y接近0(有
|
|
|
49
57
|
- `np.linspace`纯python实现
|
|
50
58
|
- `polyval`多项式代入求值
|
|
51
59
|
- `timer`计时器
|
|
60
|
+
- `is_even` `is_odd`奇偶数判断
|
|
52
61
|
### 优化算法模块`nbmath.optimize`
|
|
53
62
|
- `brute`咆哮算法
|
|
54
63
|
- `golden_section`黄金分割法
|
|
55
64
|
- `newton`牛顿法
|
|
56
65
|
- `gradient_descent`梯度下降
|
|
57
66
|
- `simulated_annealing`模拟退火
|
|
67
|
+
### 绘图模块`nbmath.plots`
|
|
68
|
+
- `point`描点 `scatter`散点图
|
|
69
|
+
- `line`线段 `fun`绘制函数F(x)
|
|
70
|
+
- `rect`矩形
|
|
71
|
+
- `mandelbrot` `heart`等共5个示例图案
|
|
58
72
|
|
|
59
73
|
## 示例代码
|
|
60
74
|
```python
|
|
61
75
|
from nbmath.equation import solve
|
|
62
76
|
from nbmath.stats import mode
|
|
63
77
|
from nbmath.optimize import simulated_annealing
|
|
78
|
+
from nbmath import plots as plt
|
|
79
|
+
import math
|
|
64
80
|
|
|
65
81
|
#求解x^4-10x^2+9=0
|
|
66
82
|
roots = solve(1, 0, -10, 0, 9)
|
|
@@ -77,7 +93,18 @@ COOLING = 0.95
|
|
|
77
93
|
STEPS = 1000
|
|
78
94
|
TOL = 1e-6
|
|
79
95
|
print(simulated_annealing(F, -5, 5, TEMP, COOLING, STEPS, TOL)) #{'x': -1.581998612252256, 'fun': -2.249992603725974}
|
|
96
|
+
|
|
97
|
+
#绘制y=cos(x)
|
|
98
|
+
plt.window(800, 600)
|
|
99
|
+
plt.setax(-2*math.pi, -1.5*math.pi, 2*math.pi, 1.5*math.pi)
|
|
100
|
+
plt.drawaxhline()
|
|
101
|
+
plt.plot_function(lambda x: math.sin(x), -2*math.pi, 2*math.pi)
|
|
102
|
+
plt.rect(1, 1, 1.5, 0.5, "red") #绘制一个左下角(1,1),长1.5,宽0.5的红色矩形
|
|
103
|
+
plt.keep_window()
|
|
80
104
|
```
|
|
81
105
|
|
|
82
106
|
## 许可证
|
|
83
107
|
MIT
|
|
108
|
+
|
|
109
|
+
**警告**
|
|
110
|
+
nbmath-1.0.0有bug,请下载nbmath-1.0.3
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from . import const
|
|
2
2
|
from . import equation
|
|
3
|
-
from . import
|
|
3
|
+
from . import geo
|
|
4
4
|
from . import plots
|
|
5
5
|
from . import stats
|
|
6
6
|
from . import utils
|
|
@@ -8,9 +8,9 @@ from . import utils
|
|
|
8
8
|
__all__ = [
|
|
9
9
|
'const',
|
|
10
10
|
'equation',
|
|
11
|
-
'
|
|
11
|
+
'geo',
|
|
12
12
|
'plots',
|
|
13
13
|
'stats',
|
|
14
14
|
'utils'
|
|
15
15
|
]
|
|
16
|
-
__version__ = "0.
|
|
16
|
+
__version__ = "1.0.4"
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import turtle as t
|
|
2
|
+
import platform
|
|
3
|
+
python_version = platform.python_version()
|
|
2
4
|
_length = _height = None
|
|
3
5
|
_llx = _lly = _urx = _ury = None
|
|
4
6
|
def window(length, height): #窗口(t.setup)
|
|
@@ -10,6 +12,8 @@ def window(length, height): #窗口(t.setup)
|
|
|
10
12
|
t.speed(0)
|
|
11
13
|
t.tracer(0)
|
|
12
14
|
t.penup()
|
|
15
|
+
print(f"Python{python_version} nbmath1.0.4")
|
|
16
|
+
print("enjoy plotting!")
|
|
13
17
|
def setax(llx, lly, urx, ury): #设置坐标系范围(t.setworldcoordinates)
|
|
14
18
|
global _llx, _lly, _urx , _ury
|
|
15
19
|
_llx, _lly, _urx , _ury = llx, lly, urx, ury
|
|
@@ -54,7 +58,7 @@ def line(x: list, y: list, color: str, linewidth: int): #绘制线段
|
|
|
54
58
|
t.goto(x[1], y[1])
|
|
55
59
|
t.pensize(1)
|
|
56
60
|
t.update()
|
|
57
|
-
def
|
|
61
|
+
def fun(f, x_min, x_max, color: str, linewidth: int, steps: int): #函数图像y=f(x)
|
|
58
62
|
t.hideturtle()
|
|
59
63
|
t.penup()
|
|
60
64
|
dx = (x_max-x_min)/steps
|
|
@@ -68,13 +72,27 @@ def plot_function(f, x_min, x_max, color: str, linewidth: int, steps: int): #函
|
|
|
68
72
|
t.pensize(linewidth)
|
|
69
73
|
t.penup()
|
|
70
74
|
t.update()
|
|
71
|
-
def scatter(points: list, color: str, size:
|
|
75
|
+
def scatter(points: list, color: str, size: list): #散点图
|
|
76
|
+
n = len(points)
|
|
77
|
+
if n!=len(size):
|
|
78
|
+
raise ValueError("length of points and size is not equal")
|
|
72
79
|
t.hideturtle()
|
|
73
80
|
t.penup()
|
|
74
81
|
t.pencolor(color)
|
|
75
|
-
for i in
|
|
76
|
-
t.goto(i)
|
|
77
|
-
t.dot(size)
|
|
82
|
+
for i in range(n):
|
|
83
|
+
t.goto(points[i])
|
|
84
|
+
t.dot(size[i])
|
|
85
|
+
t.update()
|
|
86
|
+
def rect(llx, lly, width, height, color):
|
|
87
|
+
t.hideturtle()
|
|
88
|
+
t.penup()
|
|
89
|
+
t.pencolor(color)
|
|
90
|
+
t.goto(llx, lly)
|
|
91
|
+
for i in range(2):
|
|
92
|
+
t.fd(width)
|
|
93
|
+
t.lt(90)
|
|
94
|
+
t.fd(height)
|
|
95
|
+
t.lt(90)
|
|
78
96
|
t.update()
|
|
79
97
|
def keep_window():
|
|
80
98
|
t.done()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import math
|
|
3
|
+
from nbmath.plots import core as plt
|
|
4
|
+
def F(x, depth=20):
|
|
5
|
+
if depth == 0:
|
|
6
|
+
return x
|
|
7
|
+
if x < 1/3:
|
|
8
|
+
return 0.5 * F(3*x, depth-1)
|
|
9
|
+
elif x <= 2/3:
|
|
10
|
+
return 0.5
|
|
11
|
+
else:
|
|
12
|
+
return 0.5 + 0.5 * F(3*x - 2, depth-1)
|
|
13
|
+
def main():
|
|
14
|
+
plt.window(720, 720)
|
|
15
|
+
plt.setax(-0.5, -0.5, 1.5, 1.5)
|
|
16
|
+
plt.drawaxhline()
|
|
17
|
+
plt.fun(F, 0, 1, "blue", 2, 800)
|
|
18
|
+
plt.keep_window()
|
|
19
|
+
if __name__ == "__main__":
|
|
20
|
+
main()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import sys
|
|
3
|
+
import math
|
|
4
|
+
from nbmath.plots import core as plt
|
|
5
|
+
def mandelbrot(c, max_iter=100):
|
|
6
|
+
z = 0
|
|
7
|
+
for n in range(max_iter):
|
|
8
|
+
if abs(z) > 2:
|
|
9
|
+
return n
|
|
10
|
+
z = z*z + c
|
|
11
|
+
return max_iter
|
|
12
|
+
def main():
|
|
13
|
+
width, height = 800, 600
|
|
14
|
+
xmin, xmax = -2.5, 1.5
|
|
15
|
+
ymin, ymax = -1.5, 1.5
|
|
16
|
+
plt.window(width, height)
|
|
17
|
+
plt.setax(xmin, ymin, xmax, ymax)
|
|
18
|
+
plt.drawaxhline()
|
|
19
|
+
total = width * height
|
|
20
|
+
points = []
|
|
21
|
+
for i in range(height):
|
|
22
|
+
for j in range(width):
|
|
23
|
+
x = xmin + (xmax - xmin) * j / width
|
|
24
|
+
y = ymin + (ymax - ymin) * i / height
|
|
25
|
+
c = complex(x, y)
|
|
26
|
+
iter_count = mandelbrot(c)
|
|
27
|
+
if iter_count == 100:
|
|
28
|
+
color = "black"
|
|
29
|
+
else:
|
|
30
|
+
brightness = int(255 * iter_count / 100)
|
|
31
|
+
color = f"#{brightness:02x}{brightness:02x}{brightness:02x}"
|
|
32
|
+
points.append((j, i))
|
|
33
|
+
plt.point(j, i, color, 1, "")
|
|
34
|
+
print(f"\rplotting...{i*width+j}/{total}", end="")
|
|
35
|
+
print("Ok,done.")
|
|
36
|
+
plt.keep_window()
|
|
37
|
+
if __name__ == "__main__":
|
|
38
|
+
main()
|
|
@@ -5,7 +5,7 @@ def main():
|
|
|
5
5
|
plt.window(800, 600)
|
|
6
6
|
plt.setax(-2*math.pi, -1.5*math.pi, 2*math.pi, 1.5*math.pi)
|
|
7
7
|
plt.drawaxhline()
|
|
8
|
-
plt.
|
|
8
|
+
plt.fun(lambda x:math.sin(x), -2*math.pi, 2*math.pi, "blue", 2, 800)
|
|
9
9
|
plt.keep_window()
|
|
10
10
|
if __name__ == "__main__":
|
|
11
11
|
main()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nbmath
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.4
|
|
4
4
|
Summary: python零依赖数学库
|
|
5
5
|
Author-email: tc0512 <tancheng_0812@qq.com>
|
|
6
6
|
License: MIT
|
|
@@ -16,7 +16,7 @@ Dynamic: license-file
|
|
|
16
16
|
|
|
17
17
|
## 安装
|
|
18
18
|
```bash
|
|
19
|
-
pip install https://ghproxy.net/https://github.com/tc0512/nbmath/releases/download/
|
|
19
|
+
pip install https://ghproxy.net/https://github.com/tc0512/nbmath/releases/download/v1.0.4/nbmath-1.0.4-py3-none-any.whl
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## 快速开始
|
|
@@ -24,6 +24,8 @@ pip install https://ghproxy.net/https://github.com/tc0512/nbmath/releases/downlo
|
|
|
24
24
|
from nbmath.equation import solve
|
|
25
25
|
from nbmath.const import pi
|
|
26
26
|
from nbmath.optimize import newton
|
|
27
|
+
from nbmath.utils import is_odd
|
|
28
|
+
import os
|
|
27
29
|
|
|
28
30
|
#解方程
|
|
29
31
|
print(solve(1, -3, 2)) #[(2+0j), (1+0j)]
|
|
@@ -35,6 +37,12 @@ print(pi()) #3.141592653589793
|
|
|
35
37
|
TOL = 1e-6
|
|
36
38
|
MAX_ITER = 100
|
|
37
39
|
print(newton(lambda x: x**2+6*x+9, 1.5, TOL, MAX_ITER)) #x接近-3,y接近0(有浮点误差)
|
|
40
|
+
|
|
41
|
+
#绘制康托尔阶梯
|
|
42
|
+
os.system("python -m nbmath.plots.examples.cantor_stair")
|
|
43
|
+
|
|
44
|
+
#判断是否为奇数
|
|
45
|
+
print(is_odd(99999)) #True
|
|
38
46
|
```
|
|
39
47
|
|
|
40
48
|
## 模块介绍
|
|
@@ -46,7 +54,7 @@ print(newton(lambda x: x**2+6*x+9, 1.5, TOL, MAX_ITER)) #x接近-3,y接近0(有
|
|
|
46
54
|
- 牛顿迭代法解高次方程
|
|
47
55
|
- 不等式
|
|
48
56
|
- 统一接口`solve`
|
|
49
|
-
### 几何模块`nbmath.
|
|
57
|
+
### 几何模块`nbmath.geo`
|
|
50
58
|
- 点`Point`
|
|
51
59
|
- 线段`Line`
|
|
52
60
|
- 圆`Circle`
|
|
@@ -61,18 +69,26 @@ print(newton(lambda x: x**2+6*x+9, 1.5, TOL, MAX_ITER)) #x接近-3,y接近0(有
|
|
|
61
69
|
- `np.linspace`纯python实现
|
|
62
70
|
- `polyval`多项式代入求值
|
|
63
71
|
- `timer`计时器
|
|
72
|
+
- `is_even` `is_odd`奇偶数判断
|
|
64
73
|
### 优化算法模块`nbmath.optimize`
|
|
65
74
|
- `brute`咆哮算法
|
|
66
75
|
- `golden_section`黄金分割法
|
|
67
76
|
- `newton`牛顿法
|
|
68
77
|
- `gradient_descent`梯度下降
|
|
69
78
|
- `simulated_annealing`模拟退火
|
|
79
|
+
### 绘图模块`nbmath.plots`
|
|
80
|
+
- `point`描点 `scatter`散点图
|
|
81
|
+
- `line`线段 `fun`绘制函数F(x)
|
|
82
|
+
- `rect`矩形
|
|
83
|
+
- `mandelbrot` `heart`等共5个示例图案
|
|
70
84
|
|
|
71
85
|
## 示例代码
|
|
72
86
|
```python
|
|
73
87
|
from nbmath.equation import solve
|
|
74
88
|
from nbmath.stats import mode
|
|
75
89
|
from nbmath.optimize import simulated_annealing
|
|
90
|
+
from nbmath import plots as plt
|
|
91
|
+
import math
|
|
76
92
|
|
|
77
93
|
#求解x^4-10x^2+9=0
|
|
78
94
|
roots = solve(1, 0, -10, 0, 9)
|
|
@@ -89,7 +105,18 @@ COOLING = 0.95
|
|
|
89
105
|
STEPS = 1000
|
|
90
106
|
TOL = 1e-6
|
|
91
107
|
print(simulated_annealing(F, -5, 5, TEMP, COOLING, STEPS, TOL)) #{'x': -1.581998612252256, 'fun': -2.249992603725974}
|
|
108
|
+
|
|
109
|
+
#绘制y=cos(x)
|
|
110
|
+
plt.window(800, 600)
|
|
111
|
+
plt.setax(-2*math.pi, -1.5*math.pi, 2*math.pi, 1.5*math.pi)
|
|
112
|
+
plt.drawaxhline()
|
|
113
|
+
plt.plot_function(lambda x: math.sin(x), -2*math.pi, 2*math.pi)
|
|
114
|
+
plt.rect(1, 1, 1.5, 0.5, "red") #绘制一个左下角(1,1),长1.5,宽0.5的红色矩形
|
|
115
|
+
plt.keep_window()
|
|
92
116
|
```
|
|
93
117
|
|
|
94
118
|
## 许可证
|
|
95
119
|
MIT
|
|
120
|
+
|
|
121
|
+
**警告**
|
|
122
|
+
nbmath-1.0.0有bug,请下载nbmath-1.0.3
|
|
@@ -4,7 +4,7 @@ pyproject.toml
|
|
|
4
4
|
nbmath/__init__.py
|
|
5
5
|
nbmath/const.py
|
|
6
6
|
nbmath/equation.py
|
|
7
|
-
nbmath/
|
|
7
|
+
nbmath/geo.py
|
|
8
8
|
nbmath/optimize.py
|
|
9
9
|
nbmath/stats.py
|
|
10
10
|
nbmath/utils.py
|
|
@@ -15,6 +15,8 @@ nbmath.egg-info/top_level.txt
|
|
|
15
15
|
nbmath/plots/__init__.py
|
|
16
16
|
nbmath/plots/core.py
|
|
17
17
|
nbmath/plots/examples/__init__.py
|
|
18
|
+
nbmath/plots/examples/cantor_stair.py
|
|
18
19
|
nbmath/plots/examples/heart.py
|
|
19
20
|
nbmath/plots/examples/lissajous.py
|
|
21
|
+
nbmath/plots/examples/mandelbrot.py
|
|
20
22
|
nbmath/plots/examples/sin.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|