From 586158a36dc543c9b66c04b20bfb475f24325ae0 Mon Sep 17 00:00:00 2001 From: Hussein Kabbout Date: Fri, 25 Sep 2020 17:23:54 +0200 Subject: [PATCH] Add python test dir --- test_python/main.py | 73 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 test_python/main.py diff --git a/test_python/main.py b/test_python/main.py new file mode 100644 index 0000000..0e29075 --- /dev/null +++ b/test_python/main.py @@ -0,0 +1,73 @@ +import numpy +import matplotlib.pyplot as plt + + +# matrix definition + +A = numpy.array([[1, 2, 3, 4], [2, 3, 4, 1], [3, 4, 1, 2], [4, 1, 2, 3]]) +B = numpy.array([[5, 4, 3, 2], [4, 3, 2, 5], [3, 2, 5, 4], [2, 5, 4, 3]]) +b = numpy.array([[1], [2], [3], [4]]) + + +def aufgabe_1(): + # Teilaufgabe a + print("Teilaufgabe a") + print(A @ b) + print(B @ b) + print(A.transpose()) + print(B.transpose()) + print(A.transpose() @ A) + print(B.transpose() @ B) + + # Teilaufgabe b + print("Teilaufgabe b") + print(A[3] @ B[1]) + + # Teilaufgabe c + print("Teilaufgabe c") + print(numpy.sum(A)) + print(numpy.sum(B)) + + +def aufgabe_2(): + # Abbildung 1 + plt.figure() + plt.title("Abbildung 1") + plt.xlabel("x") + plt.ylabel("y") + + x = numpy.arange(-5, 5, 0.05) + y = numpy.exp(x) + plt.plot(x, y) + + # Abbildung 2 + plt.figure() + plt.title("Abbildung 2") + plt.xlabel("x") + plt.ylabel("y") + + x = numpy.arange(-10, 10, 0.1) + y = (x ** 5 + 3 * x ** 4 + 3 * x ** 2 + x + 1) + plt.plot(x, y) + + # Abbildung 3 + plt.figure() + plt.title("Abbildung 3") + plt.xlabel("x") + plt.ylabel("y") + + x = numpy.arange(-2 * numpy.pi, 2 * numpy.pi, 0.01) + g = numpy.sin(3 * x) / 2 + h = numpy.cos(3 * x) / 2 + plt.plot(x, g) + plt.plot(x, h) + + plt.show() + + +if __name__ == "__main__": + print("Aufgabe 1") + aufgabe_1() + + print("Aufgabe 2") + aufgabe_2()