greetlib-dmitry-testlib 0.1.0__py3-none-any.whl

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.
greetlib/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from .core import *
greetlib/core.py ADDED
@@ -0,0 +1,137 @@
1
+ __all__ = ['newton', 'euler']
2
+
3
+ def newton(method_type=0):
4
+ if method_type == 0:
5
+ return '''
6
+ def newton(f, df, x0, eps=1e-6, max_iter=100):
7
+ """
8
+ f - функция
9
+ df - производная f
10
+ x0 - начальное приближение
11
+ """
12
+ x = x0
13
+ for i in range(max_iter):
14
+ fx = f(x)
15
+ dfx = df(x)
16
+
17
+ if abs(dfx) < 1e-12: # защита от деления на 0
18
+ raise "Производная слишком мала"
19
+
20
+ x_new = x - fx / dfx
21
+
22
+ if abs(x_new - x) < eps:
23
+ return x_new, i + 1
24
+
25
+ x = x_new
26
+
27
+ return print(f"Не сошелся за {max_iter} итераций")
28
+ '''
29
+ elif method_type == 1:
30
+ return '''
31
+ import math
32
+
33
+
34
+ def newton_2d(f1, f2,
35
+ df1_dx, df1_dy,
36
+ df2_dx, df2_dy,
37
+ x0, y0,
38
+ eps=1e-6, max_iter=100):
39
+ """
40
+ f1, f2 - функции f1(x, y), f2(x, y)
41
+ df1_dx, df1_dy, df2_dx, df2_dy - частные производные
42
+ x0, y0 - начальное приближение
43
+ """
44
+ x = x0
45
+ y = y0
46
+
47
+ for i in range(max_iter):
48
+ # вычисляем значения функций
49
+ f1_val = f1(x, y)
50
+ f2_val = f2(x, y)
51
+
52
+ # вычисляем частные производные
53
+ j11 = df1_dx(x, y)
54
+ j12 = df1_dy(x, y)
55
+ j21 = df2_dx(x, y)
56
+ j22 = df2_dy(x, y)
57
+
58
+ # определитель матрицы Якоби
59
+ det = j11*j22 - j12*j21
60
+
61
+ if abs(det) < 1e-15:
62
+ raise f"Определитель Якоби близок к нулю: {det}"
63
+
64
+ # обратная матрица Якоби * F
65
+ x_new = x - (f1_val*j22 - f2_val*j12) / det
66
+ y_new = y - (f2_val*j11 - f1_val*j21) / det
67
+
68
+ # критерий остановки(норма разности)
69
+ if math.sqrt((x_new - x)**2 + (y_new - y)**2) < eps:
70
+ return x_new, y_new, i + 1
71
+
72
+ x, y = x_new, y_new
73
+
74
+ return print(f"Не сошелся за {max_iter} итераций")
75
+ '''
76
+
77
+
78
+ def euler(m_type='count'):
79
+ if m_type == 'count':
80
+ return '''
81
+ def euler(f, x0, y0, x_end, h):
82
+ """
83
+ dy/dx = f(x, y)
84
+ f - правая часть f(x, y)
85
+ x0, y0 - начальное условие y(x0) = y0
86
+ x_end - конечная точка по x
87
+ h - шаг
88
+ """
89
+ x_values = [x0]
90
+ y_values = [y0]
91
+
92
+ x = x0
93
+ y = y0
94
+
95
+ while x < x_end - h/2:
96
+ y += h * f(x, y)
97
+ x += h
98
+ x_values.append(x)
99
+ y_values.append(y)
100
+
101
+ return x_values, y_values
102
+ '''
103
+ elif m_type == 'visual':
104
+ return '''
105
+ # визуализация
106
+ import matplotlib.pyplot as plt
107
+ import math
108
+
109
+ def euler(f, x0, y0, x_end, h):
110
+ x_values, y_values = [x0], [y0]
111
+ x, y = x0, y0
112
+ while x < x_end - h/2:
113
+ y += h * f(x, y)
114
+ x += h
115
+ x_values.append(x)
116
+ y_values.append(y)
117
+ return x_values, y_values
118
+
119
+ def f(x, y): return x + y
120
+ def exact(x): return 2*math.exp(x) - x - 1
121
+
122
+ # Решаем
123
+ h = 0.1
124
+ x_vals, y_vals = euler(f, 0, 1, 1, h)
125
+
126
+ # Точное решение
127
+ x_exact = [i/100 for i in range(101)]
128
+ y_exact = [exact(x) for x in x_exact]
129
+
130
+ plt.figure(figsize=(8, 5))
131
+ plt.plot(x_exact, y_exact, 'b-', linewidth=2, label='Точное решение')
132
+ plt.plot(x_vals, y_vals, 'r--', linewidth=2, marker='o', markersize=4, label=f'Эйлер (h={h})')
133
+ plt.title('Метод Эйлера: dy/dx = x + y, y(0) = 1')
134
+ plt.legend()
135
+ plt.grid(True, alpha=0.3)
136
+ plt.show()
137
+ '''
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.4
2
+ Name: greetlib-dmitry-testlib
3
+ Version: 0.1.0
4
+ Summary: Маленькая библиотека с функциями-приветствиями
5
+ Project-URL: Homepage, https://github.com/dmitry/greetlib
6
+ Author: Dmitry
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+
12
+ # greetlib
13
+
14
+ Маленькая учебная библиотека с функциями-приветствиями.
15
+
16
+ ## Установка
17
+
18
+ pip install greetlib-dmitry-testlib
19
+
20
+ ## Использование
21
+
22
+ ```python
23
+ import greetlib
24
+
25
+ print(greetlib.greet("мир")) # Привет, мир!
26
+ print(greetlib.farewell("мир")) # Пока, мир!
27
+ print(greetlib.shout("привет")) # ПРИВЕТ!
28
+ print(greetlib.whisper("ТИХО")) # (тихо)
29
+ ```
@@ -0,0 +1,6 @@
1
+ greetlib/__init__.py,sha256=K0kNy26Vm6A-1V5lST3ily6yVsNLUbiqk6AZDFm2nJI,20
2
+ greetlib/core.py,sha256=uRIJ9r7xtP9Kr0asKd3jHAl3zAllXw-5ypiHDYfmCd0,4761
3
+ greetlib_dmitry_testlib-0.1.0.dist-info/METADATA,sha256=lKG4AoICpd4xfC3fjgEhdYhrHU-93GL3bDjK_OlIKGw,813
4
+ greetlib_dmitry_testlib-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
5
+ greetlib_dmitry_testlib-0.1.0.dist-info/licenses/LICENSE,sha256=j9GKJmUNdQuKRUbKhbpv0uyMaL99xsxE6L2TDtXuaZ4,1063
6
+ greetlib_dmitry_testlib-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.30.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dmitry
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.