feat: Analysis task 8. f(x, y) Graph und Höhehnlinien
This commit is contained in:
parent
41a84d6996
commit
55fdda73b9
126
src/analysis/task8.py
Normal file
126
src/analysis/task8.py
Normal file
@ -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")
|
||||
Loading…
x
Reference in New Issue
Block a user