[NumCS] Add code (Zeros)

This commit is contained in:
RobinB27
2026-01-14 19:04:44 +01:00
parent 300448aca2
commit 7921cb36c2
4 changed files with 56 additions and 3 deletions

View File

@@ -6,3 +6,20 @@ Dann ist ein Schritt:
\begin{align*}
\tilde{F}(x) = F(x^{(k)}) + q^{(k)} (x - x^{(k)}) \Longrightarrow x^{(k + 1)} := x^{(k)} - \frac{F(x^{(k)})}{q^{(k)}}, \smallhspace \text{ falls } q^{(k)} \neq 0
\end{align*}
\innumpy Das Sekanten-Verfahren lässt sich im Prinzip ähnlich implementieren wie Newton:
\begin{code}{python}
def secant_method(f, x0: float, x1: float, tol=1e-12, maxIter=100):
""" Use secant method, which approximates the derivative """
f0 = f(x0)
for i in range(maxIter):
fn = f(x1)
secant = fn * (x1-x0) / (fn - f0) # Approximate derivative via secant
x0 = x1; x1 -= secant
if np.abs(secant) < tol: return x1, i
else: f0 = fn
return None, maxIter
\end{code}