nbmath 0.2.0__tar.gz → 0.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nbmath
3
- Version: 0.2.0
3
+ Version: 0.2.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://github.com/tc0512/nbmath/releases/download/v0.1.7/nbmath-0.1.7-py3-none-any.whl
19
+ pip install https://ghproxy.net/https://github.com/tc0512/nbmath/releases/download/v0.2.3/nbmath-0.2.3-py3-none-any.whl
20
20
  ```
21
21
 
22
22
  ## 快速开始
@@ -24,6 +24,7 @@ pip install https://github.com/tc0512/nbmath/releases/download/v0.1.7/nbmath-0.1
24
24
  from nbmath.equation import solve
25
25
  from nbmath.const import pi
26
26
  from nbmath.optimize import newton
27
+ import os
27
28
 
28
29
  #解方程
29
30
  print(solve(1, -3, 2)) #[(2+0j), (1+0j)]
@@ -35,6 +36,9 @@ print(pi()) #3.141592653589793
35
36
  TOL = 1e-6
36
37
  MAX_ITER = 100
37
38
  print(newton(lambda x: x**2+6*x+9, 1.5, TOL, MAX_ITER)) #x接近-3,y接近0(有浮点误差)
39
+
40
+ #绘制康托尔阶梯
41
+ os.system("python -m nbmath.plots.examples.cantor_stair")
38
42
  ```
39
43
 
40
44
  ## 模块介绍
@@ -67,12 +71,17 @@ print(newton(lambda x: x**2+6*x+9, 1.5, TOL, MAX_ITER)) #x接近-3,y接近0(有
67
71
  - `newton`牛顿法
68
72
  - `gradient_descent`梯度下降
69
73
  - `simulated_annealing`模拟退火
74
+ ### 绘图模块`nbmath.plots`
75
+ - `point`描点 `scatter`散点图
76
+ - `line`线段 `plot_function`绘制函数F(x)
77
+ - `mandelbrot` `heart`等共5个示例图案
70
78
 
71
79
  ## 示例代码
72
80
  ```python
73
81
  from nbmath.equation import solve
74
82
  from nbmath.stats import mode
75
83
  from nbmath.optimize import simulated_annealing
84
+ from nbmath.plots import plot_function as pf
76
85
 
77
86
  #求解x^4-10x^2+9=0
78
87
  roots = solve(1, 0, -10, 0, 9)
@@ -89,6 +98,9 @@ COOLING = 0.95
89
98
  STEPS = 1000
90
99
  TOL = 1e-6
91
100
  print(simulated_annealing(F, -5, 5, TEMP, COOLING, STEPS, TOL)) #{'x': -1.581998612252256, 'fun': -2.249992603725974}
101
+
102
+ #绘制y=cos(x)
103
+ pf()
92
104
  ```
93
105
 
94
106
  ## 许可证
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## 安装
6
6
  ```bash
7
- pip install https://github.com/tc0512/nbmath/releases/download/v0.1.7/nbmath-0.1.7-py3-none-any.whl
7
+ pip install https://ghproxy.net/https://github.com/tc0512/nbmath/releases/download/v0.2.3/nbmath-0.2.3-py3-none-any.whl
8
8
  ```
9
9
 
10
10
  ## 快速开始
@@ -12,6 +12,7 @@ pip install https://github.com/tc0512/nbmath/releases/download/v0.1.7/nbmath-0.1
12
12
  from nbmath.equation import solve
13
13
  from nbmath.const import pi
14
14
  from nbmath.optimize import newton
15
+ import os
15
16
 
16
17
  #解方程
17
18
  print(solve(1, -3, 2)) #[(2+0j), (1+0j)]
@@ -23,6 +24,9 @@ print(pi()) #3.141592653589793
23
24
  TOL = 1e-6
24
25
  MAX_ITER = 100
25
26
  print(newton(lambda x: x**2+6*x+9, 1.5, TOL, MAX_ITER)) #x接近-3,y接近0(有浮点误差)
27
+
28
+ #绘制康托尔阶梯
29
+ os.system("python -m nbmath.plots.examples.cantor_stair")
26
30
  ```
27
31
 
28
32
  ## 模块介绍
@@ -55,12 +59,17 @@ print(newton(lambda x: x**2+6*x+9, 1.5, TOL, MAX_ITER)) #x接近-3,y接近0(有
55
59
  - `newton`牛顿法
56
60
  - `gradient_descent`梯度下降
57
61
  - `simulated_annealing`模拟退火
62
+ ### 绘图模块`nbmath.plots`
63
+ - `point`描点 `scatter`散点图
64
+ - `line`线段 `plot_function`绘制函数F(x)
65
+ - `mandelbrot` `heart`等共5个示例图案
58
66
 
59
67
  ## 示例代码
60
68
  ```python
61
69
  from nbmath.equation import solve
62
70
  from nbmath.stats import mode
63
71
  from nbmath.optimize import simulated_annealing
72
+ from nbmath.plots import plot_function as pf
64
73
 
65
74
  #求解x^4-10x^2+9=0
66
75
  roots = solve(1, 0, -10, 0, 9)
@@ -77,6 +86,9 @@ COOLING = 0.95
77
86
  STEPS = 1000
78
87
  TOL = 1e-6
79
88
  print(simulated_annealing(F, -5, 5, TEMP, COOLING, STEPS, TOL)) #{'x': -1.581998612252256, 'fun': -2.249992603725974}
89
+
90
+ #绘制y=cos(x)
91
+ pf()
80
92
  ```
81
93
 
82
94
  ## 许可证
@@ -13,4 +13,4 @@ __all__ = [
13
13
  'stats',
14
14
  'utils'
15
15
  ]
16
- __version__ = "0.1.6"
16
+ __version__ = "0.2.4"
@@ -9,7 +9,8 @@ def brute(f, x_min, x_max, steps: int): #咆哮算法
9
9
  x+=step_length
10
10
  fun = min(results)
11
11
  ind = results.index(fun)
12
- return {"x": results[ind], "fun": fun}
12
+ x_opt = x_min+ind*step_length
13
+ return {"x": x_opt, "fun": fun}
13
14
  def golden_section(f, x_min, x_max, tol): #黄金分割法
14
15
  phi = (math.sqrt(5)-1)/2
15
16
  x1 = x_max-phi*(x_max-x_min)
@@ -0,0 +1,2 @@
1
+ from .core import *
2
+ from . import examples
@@ -15,6 +15,7 @@ def setax(llx, lly, urx, ury): #设置坐标系范围(t.setworldcoordinates)
15
15
  _llx, _lly, _urx , _ury = llx, lly, urx, ury
16
16
  t.setworldcoordinates(llx, lly, urx, ury)
17
17
  def drawaxhline(): #绘制坐标轴
18
+ t.hideturtle()
18
19
  global _length, _height, _llx, _lly, _urx , _ury
19
20
  if None in (_length, _height):
20
21
  raise ValueError("please use 'window' first to create a window")
@@ -35,6 +36,7 @@ def drawaxhline(): #绘制坐标轴
35
36
  t.penup()
36
37
  t.update()
37
38
  def point(x, y, color: str, size: int, label: str): #描点
39
+ t.hideturtle()
38
40
  t.penup()
39
41
  t.goto(x, y)
40
42
  t.pencolor(color)
@@ -43,6 +45,7 @@ def point(x, y, color: str, size: int, label: str): #描点
43
45
  t.penup()
44
46
  t.update()
45
47
  def line(x: list, y: list, color: str, linewidth: int): #绘制线段
48
+ t.hideturtle()
46
49
  t.penup()
47
50
  t.goto(x[0], y[0])
48
51
  t.pendown()
@@ -52,6 +55,7 @@ def line(x: list, y: list, color: str, linewidth: int): #绘制线段
52
55
  t.pensize(1)
53
56
  t.update()
54
57
  def plot_function(f, x_min, x_max, color: str, linewidth: int, steps: int): #函数图像y=f(x)
58
+ t.hideturtle()
55
59
  t.penup()
56
60
  dx = (x_max-x_min)/steps
57
61
  for i in range(steps+1):
@@ -64,12 +68,13 @@ def plot_function(f, x_min, x_max, color: str, linewidth: int, steps: int): #函
64
68
  t.pensize(linewidth)
65
69
  t.penup()
66
70
  t.update()
67
- def scatter(points: list, color: str): #散点图
71
+ def scatter(points: list, color: str, size: int): #散点图
72
+ t.hideturtle()
68
73
  t.penup()
69
74
  t.pencolor(color)
70
75
  for i in points:
71
76
  t.goto(i)
72
- t.dot(5)
77
+ t.dot(size)
73
78
  t.update()
74
79
  def keep_window():
75
80
  t.done()
@@ -0,0 +1,7 @@
1
+ from . import sin
2
+ from . import heart
3
+ from . import lissajous
4
+ from . import cantor_stair
5
+ from . import mandelbrot
6
+
7
+ __all__ = ['sin', 'heart', 'lissajous', 'cantor_stair', 'mandelbrot']
@@ -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.plot_function(F, 0, 1, "blue", 2, 800)
18
+ plt.keep_window()
19
+ if __name__ == "__main__":
20
+ main()
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env python3
2
+ import math
3
+ from nbmath.plots import core as plt
4
+ def linspace(start, end, steps):
5
+ if steps==0:
6
+ return []
7
+ elif steps==1:
8
+ return [start]
9
+ dx = (end-start)/steps
10
+ result = []
11
+ for i in range(steps+1):
12
+ x = start+i*dx
13
+ result.append(x)
14
+ return result
15
+ def main():
16
+ plt.window(720, 720)
17
+ plt.setax(-3, -3, 3, 3)
18
+ plt.drawaxhline()
19
+ A = 1
20
+ theta = linspace(-2*math.pi, 2*math.pi, 2000)
21
+ p = []
22
+ for i in theta:
23
+ r = A*(1-math.cos(i))
24
+ x = r*math.cos(i)
25
+ y = r*math.sin(i)
26
+ p.append((x, y))
27
+ plt.scatter(p, "red", 2)
28
+ plt.keep_window()
29
+ if __name__ == "__main__":
30
+ main()
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env python3
2
+ import math
3
+ from nbmath.plots import core as plt
4
+ def linspace(start, end, steps):
5
+ if steps==0:
6
+ return []
7
+ elif steps==1:
8
+ return [start]
9
+ dx = (end-start)/steps
10
+ result = []
11
+ for i in range(steps+1):
12
+ x = start+i*dx
13
+ result.append(x)
14
+ return result
15
+ def main():
16
+ plt.window(720, 720)
17
+ plt.setax(-1.5, -1.5, 1.5, 1.5)
18
+ plt.drawaxhline()
19
+ ALPHA = 1
20
+ BETA = 1
21
+ A = 5
22
+ B = 4
23
+ DELTA = math.pi/2
24
+ t = linspace(0, 2*math.pi, 5000)
25
+ p = []
26
+ for i in t:
27
+ x = ALPHA*math.sin(A*i+DELTA)
28
+ y = BETA*math.sin(B*i)
29
+ p.append((x, y))
30
+ plt.scatter(p, "green", 1)
31
+ plt.keep_window()
32
+ if __name__ == "__main__":
33
+ 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()
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env python3
2
+ import math
3
+ from nbmath.plots import core as plt
4
+ def main():
5
+ plt.window(800, 600)
6
+ plt.setax(-2*math.pi, -1.5*math.pi, 2*math.pi, 1.5*math.pi)
7
+ plt.drawaxhline()
8
+ plt.plot_function(lambda x:math.sin(x), -2*math.pi, 2*math.pi, "blue", 2, 800)
9
+ plt.keep_window()
10
+ if __name__ == "__main__":
11
+ main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nbmath
3
- Version: 0.2.0
3
+ Version: 0.2.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://github.com/tc0512/nbmath/releases/download/v0.1.7/nbmath-0.1.7-py3-none-any.whl
19
+ pip install https://ghproxy.net/https://github.com/tc0512/nbmath/releases/download/v0.2.3/nbmath-0.2.3-py3-none-any.whl
20
20
  ```
21
21
 
22
22
  ## 快速开始
@@ -24,6 +24,7 @@ pip install https://github.com/tc0512/nbmath/releases/download/v0.1.7/nbmath-0.1
24
24
  from nbmath.equation import solve
25
25
  from nbmath.const import pi
26
26
  from nbmath.optimize import newton
27
+ import os
27
28
 
28
29
  #解方程
29
30
  print(solve(1, -3, 2)) #[(2+0j), (1+0j)]
@@ -35,6 +36,9 @@ print(pi()) #3.141592653589793
35
36
  TOL = 1e-6
36
37
  MAX_ITER = 100
37
38
  print(newton(lambda x: x**2+6*x+9, 1.5, TOL, MAX_ITER)) #x接近-3,y接近0(有浮点误差)
39
+
40
+ #绘制康托尔阶梯
41
+ os.system("python -m nbmath.plots.examples.cantor_stair")
38
42
  ```
39
43
 
40
44
  ## 模块介绍
@@ -67,12 +71,17 @@ print(newton(lambda x: x**2+6*x+9, 1.5, TOL, MAX_ITER)) #x接近-3,y接近0(有
67
71
  - `newton`牛顿法
68
72
  - `gradient_descent`梯度下降
69
73
  - `simulated_annealing`模拟退火
74
+ ### 绘图模块`nbmath.plots`
75
+ - `point`描点 `scatter`散点图
76
+ - `line`线段 `plot_function`绘制函数F(x)
77
+ - `mandelbrot` `heart`等共5个示例图案
70
78
 
71
79
  ## 示例代码
72
80
  ```python
73
81
  from nbmath.equation import solve
74
82
  from nbmath.stats import mode
75
83
  from nbmath.optimize import simulated_annealing
84
+ from nbmath.plots import plot_function as pf
76
85
 
77
86
  #求解x^4-10x^2+9=0
78
87
  roots = solve(1, 0, -10, 0, 9)
@@ -89,6 +98,9 @@ COOLING = 0.95
89
98
  STEPS = 1000
90
99
  TOL = 1e-6
91
100
  print(simulated_annealing(F, -5, 5, TEMP, COOLING, STEPS, TOL)) #{'x': -1.581998612252256, 'fun': -2.249992603725974}
101
+
102
+ #绘制y=cos(x)
103
+ pf()
92
104
  ```
93
105
 
94
106
  ## 许可证
@@ -0,0 +1,22 @@
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/optimize.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
15
+ nbmath/plots/__init__.py
16
+ nbmath/plots/core.py
17
+ nbmath/plots/examples/__init__.py
18
+ nbmath/plots/examples/cantor_stair.py
19
+ nbmath/plots/examples/heart.py
20
+ nbmath/plots/examples/lissajous.py
21
+ nbmath/plots/examples/mandelbrot.py
22
+ nbmath/plots/examples/sin.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "nbmath"
7
- version = "0.2.0"
7
+ version = "0.2.4"
8
8
  description = "python零依赖数学库"
9
9
  authors = [
10
10
  {name = "tc0512", email = "tancheng_0812@qq.com"}
@@ -1,15 +0,0 @@
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/optimize.py
9
- nbmath/plots.py
10
- nbmath/stats.py
11
- nbmath/utils.py
12
- nbmath.egg-info/PKG-INFO
13
- nbmath.egg-info/SOURCES.txt
14
- nbmath.egg-info/dependency_links.txt
15
- nbmath.egg-info/top_level.txt
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes