diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..ba2a6c013 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "python-envs.defaultEnvManager": "ms-python.python:system", + "python-envs.pythonProjects": [] +} \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index f1ec59983..000000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Базовый курс (моделирование на python) -Репозиторий для прохождения базового курса по языку программирования python, -в рамках общего цикла лекций "Моделирование на python". diff --git a/__pycache__/lec_numpy.cpython-312.pyc b/__pycache__/lec_numpy.cpython-312.pyc new file mode 100644 index 000000000..e1b38f7a9 Binary files /dev/null and b/__pycache__/lec_numpy.cpython-312.pyc differ diff --git a/__pycache__/numpy.cpython-312.pyc b/__pycache__/numpy.cpython-312.pyc new file mode 100644 index 000000000..d0e21b0df Binary files /dev/null and b/__pycache__/numpy.cpython-312.pyc differ diff --git a/lec_generators.py b/lec_generators.py new file mode 100644 index 000000000..62200ea23 --- /dev/null +++ b/lec_generators.py @@ -0,0 +1,12 @@ +import numpy as np + +a = range(0, 5, 1) +print(a) + +# a = range(0, 10, 0.1) + +b = np.arange(0, 5, 0.1) #хранит массив с данными. как рандж включает старт, не включает стоп +print(b) + +d = np.linspace(0, 5, 10) #включает старт, включает стоп, хранит массивы +print(d) \ No newline at end of file diff --git a/lec_import.py b/lec_import.py new file mode 100644 index 000000000..913f5dd9b --- /dev/null +++ b/lec_import.py @@ -0,0 +1,11 @@ +# Модуль lec_import.py + +# Инструкция, целиком загружающая модуль +import lec_my_module + +print(lec_my_module.a) #точка - это оператор, предоставляющий доступ к атрибутам объектов + +b = lec_my_module.b * 3 +print(b) + +print(lec_my_module.c[2]) \ No newline at end of file diff --git a/lec_import_as.py b/lec_import_as.py new file mode 100644 index 000000000..c740cfdc8 --- /dev/null +++ b/lec_import_as.py @@ -0,0 +1,8 @@ +import lec_my_module as mm + +print(mm.a) + +b = mm.b * 3 +print(b) + +print(mm.c[2] + b + mm.c[0]) \ No newline at end of file diff --git a/lec_import_false.py b/lec_import_false.py new file mode 100644 index 000000000..e41035345 --- /dev/null +++ b/lec_import_false.py @@ -0,0 +1,9 @@ +from lec_my_module import b +from lec_import_as import b + +print(b) + +import lec_my_module as mm +import lec_import_as as l3 + +print(mm.b + l3.b) \ No newline at end of file diff --git a/lec_import_from.py b/lec_import_from.py new file mode 100644 index 000000000..1ace5fac8 --- /dev/null +++ b/lec_import_from.py @@ -0,0 +1,9 @@ +# Копирование указанных атрибутов модуля +from lec_my_module import a, b + +print(a * b) + +# Копирование ВСЕХ атрибутов модуля +from lec_my_module import * + +print(c[2] * c[1]) \ No newline at end of file diff --git a/lec_import_from_as.py b/lec_import_from_as.py new file mode 100644 index 000000000..10a4a82fc --- /dev/null +++ b/lec_import_from_as.py @@ -0,0 +1,9 @@ +from lec_my_module import earth_mass as em +from lec_my_module import gravity_constant as G +from lec_my_module import sigma_steff_bolc as sigma + +g = 500 * G / 10 ** 2 +print(g) + +x = em * G * sigma +print(x) \ No newline at end of file diff --git a/lec_math.py b/lec_math.py new file mode 100644 index 000000000..fc24b8bae --- /dev/null +++ b/lec_math.py @@ -0,0 +1,13 @@ +import math + +a = math.sin(3 * math.pi / 5) +print(a) + +b = math.sqrt(3) +print(b) + +c = math.log10(42) +print(c) + +d = math.asin(math.tan(math.pi / 4)) * 180 / math.pi +print(d) \ No newline at end of file diff --git a/lec_my_module.py b/lec_my_module.py new file mode 100644 index 000000000..1f7997f1b --- /dev/null +++ b/lec_my_module.py @@ -0,0 +1,11 @@ +# Модуль lec_my_module.py + +# Атрибуты модуля +a = 3 +b = 'Good' +c = ['Bad', 4, 'Petya molodec'] + +earth_mass = 5.97 * 10 ** 30 +sigma_steff_bolc = 5.67 * 10 ** (-8) +gravity_constant = 6.67 * 10 ** (-11) + diff --git a/lec_np.array.py b/lec_np.array.py new file mode 100644 index 000000000..b7cf29ccc --- /dev/null +++ b/lec_np.array.py @@ -0,0 +1,16 @@ +import lec_numpy as np + +a = [1, 2, 4] + +b = np.array(a) # Создание массива из списка + +print(type(a)) +print(type(b)) + +print(b * b) +print(b / b) +print(b - b) + +# print(a - a) + +print(b[-1]) # Вызов последнего элеманта массива \ No newline at end of file diff --git a/lec_np.zeros_np.ones_np.ndarray.py b/lec_np.zeros_np.ones_np.ndarray.py new file mode 100644 index 000000000..082e8105b --- /dev/null +++ b/lec_np.zeros_np.ones_np.ndarray.py @@ -0,0 +1,17 @@ +import lec_numpy as np + +a = np.zeros((2, 3)) +print(a) + +a[0, 2] = 5 +print(a) + +b = np.ones((3, 2)) +print(b) + +c = np.ndarray((3, 3)) +print(c) + +print(type(a)) +print(type(b)) +print(type(c)) \ No newline at end of file diff --git a/lec_numpy.py b/lec_numpy.py new file mode 100644 index 000000000..25957058c --- /dev/null +++ b/lec_numpy.py @@ -0,0 +1,43 @@ +import numpy as np + +#3*x+2*y=7 +#5x-3y=-1 +#Ax = B => x = A^(-1)*B + +A = np.array([[3,2],[5,-3]], dtype='float') +B = np.array([[7],[-1]], dtype='float') + +print(A) +print(B) + +A_inv = np.linalg.inv(A) #A-1 +print(A_inv) + +print(A @ A_inv) + +x = A_inv @ B +print(x) + +""" +3x+5y+4z=23 +-5x+2y-4z=11 +-2x-3y-5z=-5 +""" + +A = np.array([[3,5,4],[-5,2,-4],[-2,-3,-5]], dtype='float') +B = np.array([[23],[11],[-5]], dtype='float') +print(A) +print(B) + +A_inv = np.linalg.inv(A) #A-1 +print(A_inv) +print(A @ A_inv) +x = A_inv @ B +print(x) + +print('тоже самое при поомщи метода solve') + +print(np.linalg.solve(A,B)) + +print(A@x) +print(B) diff --git a/lec_slice.py b/lec_slice.py new file mode 100644 index 000000000..5a158f3ab --- /dev/null +++ b/lec_slice.py @@ -0,0 +1,17 @@ +import numpy as np + +a = [1, 5, 3, 6] +slice = a[0:2:1] #старт:стоп:step +print(slice) + +slice = a[3:0:-1] +print(slice) + +slice = a[::-1] +print(slice) + +b = np.array([a, np.array(a) * 3]) +print(b) + +slice = b[::, 1] +print(slice) \ No newline at end of file diff --git a/lec_task1.py b/lec_task1.py new file mode 100644 index 000000000..8d2501cfe --- /dev/null +++ b/lec_task1.py @@ -0,0 +1,12 @@ +import numpy as np + +a = [[2,3,1,4,5,6,7],[8,1,3,2,2,6,8],[1,4,3,1,0,2,5],[4,5,0,1,3,2,1],[8,7,9,1,0,2,3]] + + +slice1 = a[0:3:,0:4:] #старт:стоп:step +slice2 = a[1:3:,3:6:] +slice3 = a[0:4:,6::] +slice4 = a[5::,0:2:] +slice5 = a[4::,2:4:] +slice6 = a[3:5:,5::] +print(slice1) \ No newline at end of file diff --git a/lec_task3.py b/lec_task3.py new file mode 100644 index 000000000..ea529949d --- /dev/null +++ b/lec_task3.py @@ -0,0 +1,51 @@ +import numpy as np +import time +g=9.8 +t=0 + +x0=0 +y0=0 +vox=6 +voy=7 + +a=[] +while t in range(0,5): + t+=1 + x=x0+vox*t + y=y0+voy*t-((g*t**2)/2) + b = [x,round(y,1),t] + #print(b) + a.append(b) +print(a) + +v=5 +alpha=np.pi/180*45 +vx_0=v*np.cos(alpha) +vy_0=v*np.sin(alpha) + +timer = time.time() +coords = [] +for t in np.arange(0,5,0.00001): + x=x0+vx_0*t + y=y0+vy_0*t-((g*t**2)/2) +coords=np.array(coords) +print(coords) +print(time.time()-timer) + +timer = time.time() +step=0.00001 +t=np.arange(0,5,step) +x=x0+vx_0*t +y=y0+vy_0*t-((g*t**2)/2) +coords = np.zeros((len(t),3)) +coords[:,0]=t +coords[:,1]=x +coords[:,2]=y +print(coords) +print(time.time()-timer) + + +timer = time.time() + + +