From 55fdda73b9cb2f9c1a59bf4df05057572800503e Mon Sep 17 00:00:00 2001 From: zimmersandro Date: Sun, 26 Apr 2026 16:58:36 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Analysis=20task=208.=20f(x,=20y)=20Grap?= =?UTF-8?q?h=20und=20H=C3=B6hehnlinien?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/analysis/task8.py | 126 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 src/analysis/task8.py diff --git a/src/analysis/task8.py b/src/analysis/task8.py new file mode 100644 index 0000000..8237294 --- /dev/null +++ b/src/analysis/task8.py @@ -0,0 +1,126 @@ +# %% +# Init +import numpy as np +import matplotlib.pyplot as plt + +# Parameter +N = 401 # Anzahl Intervalle für x- bzw. y-Achsen +N_g = 10 # Schrittweite +N_l = 31 # Schrittweite + + +def get_parameter() -> list: + """Funktion gibt eine List mit Dictonaries als Rückgabe. + Jede Dictonary enhält die Funktion f(x,y) und Parameter für den Plot der Funktion + + Returns: + list: + dict: + "f": Funktion f(x, y), + "x_0": Startwert der x-Achse + "x_E": Endwert der x-Achse + "y_0": Startwert der y-Achse + "y_E": Endwert der y-Achse + "az": Dregwubjek gegebübver z-Achse (azimuth) und gegenüber xy-Ebene + "el": Dregwubjek gegebübver z-Achse (azimuth) und gegenüber xy-Ebene + "fig": Figurbezeichnung für pyplot + """ + return [ + { + "f": lambda x, y: x / 2, + "x_0": -2, + "x_E": 2, + "y_0": -2, + "y_E": 2, + "az": 60, + "el": 25, + "fig": "a", + }, + { + "f": lambda x, y: y / 2, + "x_0": -2, + "x_E": 2, + "y_0": -2, + "y_E": 2, + "az": -35, + "el": 30, + "fig": "b", + }, + { + "f": lambda x, y: (x + y) / 2, + "x_0": -2, + "x_E": 2, + "y_0": -2, + "y_E": 2, + "az": -35, + "el": 30, + "fig": "c", + }, + { + "f": lambda x, y: x * y / 4, + "x_0": -3, + "x_E": 3, + "y_0": -3, + "y_E": 3, + "az": -105, + "el": 15, + "fig": "d", + }, + { + "f": lambda x, y: (x**2 + y**2) / 2, + "x_0": -2, + "x_E": 2, + "y_0": -2, + "y_E": 2, + "az": -35, + "el": 20, + "fig": "e", + }, + { + "f": lambda x, y: 6 * np.sin(x * y) / (1 + x**2 + y**2), + "x_0": -2, + "x_E": 2, + "y_0": -2, + "y_E": 2, + "az": -35, + "el": 40, + "fig": "f", + }, + ] + + +# Main +for parameter in get_parameter(): + # Daten + f = parameter["f"] + x_0 = parameter["x_0"] + x_E = parameter["x_E"] + y_0 = parameter["y_0"] + y_E = parameter["y_E"] + az = parameter["az"] + el = parameter["el"] + fig = parameter["fig"] + + x_data = np.linspace(x_0, x_E, N) # Punkte auf der x-Achse + y_data = np.linspace(y_0, y_E, N) # Punkte auf der y-Achse + + [x_grid, y_grid] = np.meshgrid(x_data, y_data) # Pärchen mit allen x- und y-Werten + z_grid = f(x_grid, y_grid) # Funktionswerte der Pärchen + + # Graph-Plot + plt.figure(fig) + ax = plt.axes(projection="3d") + ax.plot_surface(x_grid, y_grid, z_grid, rstride=N_g, cstride=N_g, cmap="rainbow") + ax.view_init(el, az) + ax.set_box_aspect((np.ptp(x_grid), np.ptp(y_grid), np.ptp(z_grid))) + plt.title("3D Darstellung") + + # Höhenlinien-Plot + figh = fig + "h" + fh = plt.figure(figh) + plt.contour(x_grid, y_grid, z_grid, N_l) + plt.xlabel("x") + plt.ylabel("y") + plt.grid(False) + plt.axis("image") + plt.title("Höhenlinien")