Compare commits
No commits in common. "18d7e8cdb5968d9c75631af9e374d31151d62c08" and "c241c2c6954a2bec9ad4079ebf426026f727cadd" have entirely different histories.
18d7e8cdb5
...
c241c2c695
@ -1,15 +1,14 @@
|
||||
# %%
|
||||
#%%
|
||||
import numpy as np
|
||||
|
||||
# %%
|
||||
print("Aufgabe 4")
|
||||
|
||||
|
||||
def fixpunkt_iteration(f, x=1.0, tol=1e-7, N=1000):
|
||||
x_new = f(x)
|
||||
i = 0
|
||||
|
||||
while np.abs(x_new - x) > tol:
|
||||
while(np.abs(x_new-x) > tol):
|
||||
if i > N:
|
||||
raise RuntimeError("Keine Konvergenz erreicht")
|
||||
|
||||
@ -18,21 +17,18 @@ def fixpunkt_iteration(f, x=1.0, tol=1e-7, N=1000):
|
||||
i += 1
|
||||
return [x_new, i]
|
||||
|
||||
|
||||
# Ausgabe
|
||||
print("----------------------------------------------------------------------")
|
||||
print(__file__)
|
||||
print("----------------------------------------------------------------------")
|
||||
|
||||
f = lambda x: 1 - (1 / 5) * x
|
||||
f = lambda x: 1-(1/5)*x
|
||||
try:
|
||||
fixpunkt_a, iterationen_a = fixpunkt_iteration(f)
|
||||
except RuntimeError as error:
|
||||
print(f"a) f(x) = 1-(1/5)*x\n{error}")
|
||||
else:
|
||||
print(
|
||||
f"a) f(x) = 1-(1/5)*x\nFixpunkt: {fixpunkt_a}\nIterationen: {iterationen_a}\n"
|
||||
)
|
||||
print(f"a) f(x) = 1-(1/5)*x\nFixpunkt: {fixpunkt_a}\nIterationen: {iterationen_a}\n")
|
||||
|
||||
f = np.cos
|
||||
try:
|
||||
@ -51,38 +47,3 @@ else:
|
||||
print(f"c) f(x) = e⁻x\nFixpunkt: {fixpunkt_c}\nIterationen: {iterationen_c}\n")
|
||||
|
||||
print("----------------------------------------------------------------------")
|
||||
|
||||
##%
|
||||
# Parameter
|
||||
q = 2.0
|
||||
a_0 = 1.0
|
||||
pr = 16
|
||||
|
||||
|
||||
# Funktionen
|
||||
def f(x):
|
||||
y = 0.5 * (x + q / x)
|
||||
return y
|
||||
|
||||
|
||||
# Iteration
|
||||
w = 0.0
|
||||
a = a_0
|
||||
k = 0
|
||||
|
||||
print("----------------------------------------------------------------------")
|
||||
print(__file__)
|
||||
print("----------------------------------------------------------------------")
|
||||
print("Iteration :")
|
||||
print(f"a_{k} = {a:#.16g}")
|
||||
|
||||
while a != w:
|
||||
w = a
|
||||
k = k + 1
|
||||
a = f(a)
|
||||
print(f"a_{k} = {a:#.16g}")
|
||||
|
||||
# Ausgabe :
|
||||
print("----------------------------------------------------------------------")
|
||||
print(f"Wurzel: sqrt({q:#.{pr}g}) = {a:#.{pr}g}")
|
||||
print("----------------------------------------------------------------------")
|
||||
Loading…
x
Reference in New Issue
Block a user