commit 744a0b8410f88c6f4fd6652d960d1dd3bf75fe35 Author: timur Date: Fri Oct 13 17:07:25 2023 +0300 TASK2 diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/Task2_excel.xlsx b/Task2_excel.xlsx new file mode 100644 index 0000000..de3548b Binary files /dev/null and b/Task2_excel.xlsx differ diff --git a/test_function1.py b/test_function1.py new file mode 100644 index 0000000..d46c227 --- /dev/null +++ b/test_function1.py @@ -0,0 +1,28 @@ +import time + +def linspace(start, stop, n): + if n == 1: + yield stop + return + h = (stop - start) / (n - 1) + for i in range(n): + yield start + h * i + +def mandelbrot(pmin = -2.5, pmax= 1.5, qmin = -2, qmax= 2, + ppoints = 200, qpoints = 200, max_iterations = 300, infinity_border = 100): + image = [[0 for i in range(qpoints)] for j in range(ppoints)] + for ip, p in enumerate(linspace(pmin, pmax, ppoints)): + for iq, q in enumerate(linspace(qmin, qmax, qpoints)): + c = p + 1j * q + z = 0 + for k in range(max_iterations): + z = z ** 2 + c + if abs(z) > infinity_border: + image[ip][iq] = 1 + break + return image + +tic = time.perf_counter_ns() +image = mandelbrot() +toc = time.perf_counter_ns() +print((toc - tic)/1_000_000_000, "s") diff --git a/test_function2.py b/test_function2.py new file mode 100644 index 0000000..3a17018 --- /dev/null +++ b/test_function2.py @@ -0,0 +1,30 @@ +import time + +def linspace(start, stop, n): + if n == 1: + yield stop + return + h = (stop - start) / (n - 1) + for i in range(n): + yield start + h * i + +def mandelbrot(pmin: float = -2.5, pmax: float = 1.5, qmin: float = -2, qmax: float = 2, + ppoints: int = 200, qpoints: int = 200, max_iterations: int = 300, infinity_border: float = 100) -> list[list[int]]: + + image: list[list[int]] = [[0 for i in range(qpoints)] for j in range(ppoints)] + for ip, p in enumerate(linspace(pmin, pmax, ppoints)): + for iq, q in enumerate(linspace(qmin, qmax, qpoints)): + c: complex = p + 1j * q + z: complex = 0 + for k in range(max_iterations): + z = z ** 2 + c + if abs(z) > infinity_border: + image[ip][iq] = 1 + break + return image + +tic = time.perf_counter_ns() +image = mandelbrot() +toc = time.perf_counter_ns() +print((toc - tic)/1_000_000_000, "s") + diff --git a/test_function3.py b/test_function3.py new file mode 100644 index 0000000..87ab01d --- /dev/null +++ b/test_function3.py @@ -0,0 +1,24 @@ +import time +import numpy as np + +def mandelbrot(pmin = -2.5, pmax = 1.5, qmin = -2, qmax = 2, + ppoints = 200, qpoints = 200, max_iterations = 300, infinity_border= 100): + + image = np.zeros((ppoints, qpoints)) + + for ip, p in enumerate(np.linspace(pmin, pmax, ppoints)): + for iq, q in enumerate(np.linspace(qmin, qmax, qpoints)): + c = p + 1j * q + z = 0 + for k in range(max_iterations): + z = z ** 2 + c + if abs(z) > infinity_border: + + image[ip, iq] = 1 + break + return image + +tic = time.perf_counter_ns() +image = mandelbrot() +toc = time.perf_counter_ns() +print((toc - tic)/1_000_000_000, "s")