From fe8866f1df56215391c8daeb0eaacbb7bb73f2f8 Mon Sep 17 00:00:00 2001 From: git-sandro Date: Thu, 26 Feb 2026 22:42:18 +0100 Subject: [PATCH] feat: aufgabe 4 abgeschlossen --- introduction/serie_2.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 introduction/serie_2.py diff --git a/introduction/serie_2.py b/introduction/serie_2.py new file mode 100644 index 0000000..e6811ae --- /dev/null +++ b/introduction/serie_2.py @@ -0,0 +1,35 @@ +#%% +import numpy as np + +# %% +print("Aufgabe 4") + +def fixpunkt_iteration(f, x, tol=1e-7): + x_new = f(x) + i = 0 + + while(np.abs(x_new-x) > tol): + x = x_new + x_new = f(x) + i += 1 + return [x_new, i] + +x0 = 1.0 + +f = lambda x: 1-(1/5)*x +fixpunkt_a, iterationen_a = fixpunkt_iteration(f, x0) + +f = np.cos +fixpunkt_b, iterationen_b = fixpunkt_iteration(f, x0) + +f = lambda x: np.e**-x +fixpunkt_c, iterationen_c = fixpunkt_iteration(f, x0) + +# Ausgabe +print("----------------------------------------------------------------------") +print(__file__) +print("----------------------------------------------------------------------") +print(f"a) f(x) = 1-(1/5)*x\nFixpunkt: {fixpunkt_a}\nIterationen: {iterationen_a}\n") +print(f"b) f(x) = cos(x)\nFixpunkt: {fixpunkt_b}\nIterationen: {iterationen_b}\n") +print(f"c) f(x) = e⁻x\nFixpunkt: {fixpunkt_c}\nIterationen: {iterationen_c}\n") +print("----------------------------------------------------------------------")