mirror of
https://github.com/janishutz/eth-summaries.git
synced 2026-03-14 17:00:05 +01:00
26 lines
960 B
TeX
26 lines
960 B
TeX
\newsectionNoPB
|
|
\subsection{Sekantenverfahren}
|
|
Falls die Ableitung zu teuer oder nicht verfügbar ist, kann man sie durch $q^(k) := \frac{F(x^{(k)}) - F(x^{(k - 1)})}{x^{(k)} - x^{(k - 1)}}$.
|
|
Dann ist ein Schritt:
|
|
\rmvspace
|
|
\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}
|