From 88f29d1f52eaad0b1012a6ddff96976a1c364c86 Mon Sep 17 00:00:00 2001 From: git-sandro Date: Tue, 24 Feb 2026 23:09:15 +0100 Subject: [PATCH] feat: introduction/serie_1.py advanced. docs: README altered. feat: requirements.txt added --- README.md | 5 +-- introduction/serie_1.py | 83 ++++++++++++++++++++++++++++++++++++++++- requirements.txt | 2 + 3 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 requirements.txt diff --git a/README.md b/README.md index 01b703f..5cd5a34 100644 --- a/README.md +++ b/README.md @@ -1,4 +1 @@ -Repository for CDS-404 Numerische Methoden - -Required libraries: -* numpy \ No newline at end of file +Repository for CDS-404 Numerische Methoden \ No newline at end of file diff --git a/introduction/serie_1.py b/introduction/serie_1.py index 7252e1f..1f553b7 100644 --- a/introduction/serie_1.py +++ b/introduction/serie_1.py @@ -1,5 +1,8 @@ +#%% +# Numpy initialisieren import numpy as np +import matplotlib.pyplot as plt #%% print("Aufgabe 2") print(f"a) {1/3}") @@ -25,5 +28,81 @@ print(f"k) {1 / np.arctan(34.1)}") print(f"l) {np.power(np.array([np.e]), -3.34)}") print(f"m) {np.e}") print(f"n) {np.log(13.2)}") -print(f"o) ") -print(f"p) ") +print(f"o) {np.log10(23)}") +print(f"p) {np.log2(69.6)}") + +# %% +print("Aufgabe 7") +# Parameter +a = 12.3, b = 8.14, pr = 3, ME = "cm" + +# Berechnungen +c = np.sqrt(a**2+b**2) + +# Ausgabe +print("----------------------------------------------------------------------") +print(__file__) +print("----------------------------------------------------------------------") +print(f"Seite a = {a:#.{pr}g} {ME}") +print(f"Seite b = {b:#.{pr}g} {ME}") +print(f"Seite c = {c:#.{pr}g} {ME}") +print("----------------------------------------------------------------------") + +# %% +print("Aufgabe 7.d)") +# Parameter +a = 0.85e3; pr_a = 2; sc_a = 1.0e-3; ME_a = "km";\ +b = 234; pr_b = 3; sc_b = 1.0; ME_b = "m";\ + pr_c = 2; sc_c = 1.0e-3; ME_c = "km";\ + +# Berechnungen +c = np.sqrt(a**2+b**2) + +# Ausgabe +print("----------------------------------------------------------------------") +print(__file__) +print("----------------------------------------------------------------------") +print(f"Seite a = {a*sc_a:#.{pr_a}g} {ME_a}") +print(f"Seite b = {b*sc_b:#.{pr_b}g} {ME_b}") +print(f"Seite c = {c*sc_c:#.{pr_c}g} {ME_c}") +print("----------------------------------------------------------------------") + +# %% +print("Aufgabe 8") +# Python konfigurieren +plt.close("all") +plt.rcParams["figure.figsize"] = (7.03,15) +plt.rcParams["font.size"] = 9 +plt.rcParams["font.family"] = "serif" +plt.rcParams["text.usetex"] = False + +# Parameter +x_0 = 0 +x_E = 4 +N = 201 +lw = 3 +fig = 1 + +# Funktionen +def f(x): + y = 3/(1+x) + return y + +def g(x): + y = x/2 + return y + +# Daten +x_data = np.linspace(x_0, x_E, N) +f_data = f(x_data) +g_data = g(x_data) + +# pltot +fh = plt.figure(fig) +plt.plot(x_data, f_data, linewidth = lw, label = r"$f$") +plt.plot(x_data, g_data, "--", linewidth = lw, label = r"$g$") +plt.xlabel(r"$x$") +plt.ylabel(r"$y$") +plt.legend() +plt.grid(visible=True) +plt.axis("image") \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..806f221 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +numpy +matplotlib \ No newline at end of file