mirror of
https://github.com/janishutz/eth-summaries.git
synced 2026-03-14 10:50:05 +01:00
[NumCS] Add code (Zeros)
This commit is contained in:
@@ -15,3 +15,17 @@ Beim Newtonverfahren verwendet man für jeden Iterationsschritt die lineare Funk
|
||||
|
||||
\drmvspace
|
||||
falls $F(x^*) = 0$ und $F^(x^*) \neq 0$
|
||||
|
||||
\newpage
|
||||
|
||||
\innumpy Ist das Newton-Verfahren mit sehr wenig code implementierbar:
|
||||
|
||||
\begin{code}{python}
|
||||
def newton_method(f, df, x: float, tol=1e-12, maxIter=100):
|
||||
""" Use Newton's method to find zeros, requires derivative of f """
|
||||
iter = 0
|
||||
while (np.abs(df(x)) > tol and iter < maxIter):
|
||||
x -= f(x)/df(x); iter += 1
|
||||
|
||||
return x, iter
|
||||
\end{code}
|
||||
|
||||
Reference in New Issue
Block a user