feat: newton verfahren für cos funktion
This commit is contained in:
parent
a83a731cdc
commit
59149464c4
@ -8,7 +8,8 @@ N = 200
|
||||
x = sp.Symbol("x")
|
||||
|
||||
# Funktion
|
||||
f_sym = x**4 - 10 * x**2 + x
|
||||
# f_sym = x**4 - 10 * x**2 + x
|
||||
f_sym = -sp.cos(2 * sp.pi * x)
|
||||
|
||||
# Ableitungen
|
||||
f = sp.lambdify(x, f_sym, "numpy")
|
||||
@ -16,7 +17,8 @@ f_prime = sp.lambdify(x, sp.diff(f_sym, x), "numpy")
|
||||
f_second = sp.lambdify(x, sp.diff(f_sym, x, 2), "numpy")
|
||||
|
||||
# Daten
|
||||
x_data = np.linspace(-4, 4, N)
|
||||
# x_data = np.linspace(-4, 4, N)
|
||||
x_data = np.linspace(-3, 3, N)
|
||||
f_data = f(x_data)
|
||||
|
||||
# Plot
|
||||
@ -29,11 +31,12 @@ plt.show()
|
||||
|
||||
# Newton Verfahren
|
||||
# Startwert
|
||||
startwerte = [0.1]
|
||||
startwerte = [0.01, 0.02, 0.05, 0.1, 0.2, 0.23, 0.24, 0.245, 0.248, 0.249, 0.2499]
|
||||
|
||||
# Iterationsformel
|
||||
x_n = lambda x: x - f_prime(x) / np.abs(f_second(x))
|
||||
|
||||
print(60 * "-")
|
||||
# Iteration
|
||||
for x_0 in startwerte:
|
||||
n = 0
|
||||
@ -51,4 +54,5 @@ for x_0 in startwerte:
|
||||
f_x_second = f_second(x_i)
|
||||
print(f"x_{n}: {x_i}\nf'(x_{n}): {f_x_prime}\nf''(x_{n}): {f_x_second}\n")
|
||||
limit -= 1
|
||||
print(60 * "-")
|
||||
# %%
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user