mirror of
https://github.com/janishutz/eth-summaries.git
synced 2026-03-14 10:50:05 +01:00
[NumCS] Add code (Broyden)
This commit is contained in:
@@ -16,14 +16,13 @@ Wichtig ist dabei, dass wir \bi{niemals} das Inverse der Jacobi-Matrix (oder irg
|
||||
sondern immer das Gleichungssystem $As = b$ lösen sollten, da dies effizienter ist:
|
||||
|
||||
\begin{code}{python}
|
||||
def newton(x, F, DF, tol=1e-12, maxit=50):
|
||||
x = np.atleast_2d(x) # ’solve’ erwartet x als 2-dimensionaler numpy array
|
||||
# Newton Iteration
|
||||
for _ in range(maxit):
|
||||
s = np.linal.solve(DF(x), F(x))
|
||||
def newton_2d(x: np.ndarray, F, DF, tol=1e-12, maxIter=50):
|
||||
""" Newton method in 2d using Jacobi Matrix of F"""
|
||||
for i in range(maxIter):
|
||||
s = np.linalg.solve(DF(x[0], x[1]), F(x[0], x[1]))
|
||||
x -= s
|
||||
if np.linalg.norm(s) < tol * np.linalg.norm(x):
|
||||
return x
|
||||
if np.linalg.norm(s) < tol * np.linalg.norm(x): return x, i
|
||||
return x, maxIter
|
||||
\end{code}
|
||||
|
||||
Wollen wir aber garantiert einen Fehler kleiner als unsere Toleranz $\tau$ können wir das Abbruchkriterium
|
||||
|
||||
Reference in New Issue
Block a user