Add python test dir

This commit is contained in:
Hussein Kabbout 2020-09-25 17:23:54 +02:00
parent 455769b152
commit 586158a36d

73
test_python/main.py Normal file
View File

@ -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()