Skip to content

Commit 142c6e3

Browse files
committed
Post-lecture fixes
1 parent 952fe56 commit 142c6e3

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/07_Iterative_methods.jl

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ md"""Let us consider the test problem $\textbf{A} \textbf{x} = \textbf{b}$ with"
159159

160160
# ╔═╡ 1c4ba2a0-553f-4b35-8b45-3de1c9e3a4e8
161161
# Generate a random matrix, which has large entries on the diagonal
162-
A = randn(100, 100) + Diagonal(10 .+ 50rand(100))
162+
A = randn(100, 100) + Diagonal(15 .+ 50rand(100))
163163

164164
# ╔═╡ 49134b41-d3ca-4286-ae9a-5be0d1569241
165165
b = rand(100);
@@ -366,10 +366,13 @@ then $\|\mathbf{B}\| = \|\mathbf{I} - \mathbf{A}\|$
366366
becomes
367367
"""
368368

369+
# ╔═╡ e277ff4c-87a8-440d-bba4-f30a20b47788
370+
A
371+
369372
# ╔═╡ 54cb29d7-4933-4ab4-a3b5-26431d8432f9
370373
let
371374
B = I - A # Iteration matrix for P = I, i.e. no preconditioner
372-
norm_b = sqrt(maximum( B' * B ))
375+
norm_b = sqrt(maximum(eigvals( B' * B )))
373376
end
374377

375378
# ╔═╡ af630960-a734-4124-81d3-a2657456f6c2
@@ -383,7 +386,7 @@ then
383386
let
384387
P = Diagonal(A)
385388
B = I - inv(P) * A # Iteration matrix for P = Diagonal(A)
386-
norm_b = sqrt(maximum( B' * B ))
389+
norm_b = sqrt(maximum(eigvals( B' * B )))
387390
end
388391

389392
# ╔═╡ 114bc28c-7888-4c6c-85bd-8c6232624491
@@ -395,12 +398,13 @@ Therefore only the preconditioned iterations converge:
395398
# ╔═╡ d8e0e584-985d-4ff0-8a5c-b21c83c226d9
396399
let
397400
P = Diagonal(A)
398-
richardson_diagonal = richardson(A, b, P; tol=1e-6, maxiter=30)
399-
richardson_no_preconditioner = richardson(A, b, I; tol=1e-6, maxiter=30)
401+
richardson_diagonal = richardson(A, b, P; tol=1e-10, maxiter=30)
402+
richardson_no_preconditioner = richardson(A, b, I; tol=1e-10, maxiter=30)
400403

401404
plot(richardson_diagonal.history;
402405
yaxis=:log, mark=:o, lw=2, ylabel=L"||r|| / ||b||",
403-
label=L"$P = \textrm{Diagonal(}A\textrm{)}$", legend=:bottomright)
406+
label=L"$P = \textrm{Diagonal(}A\textrm{)}$", legend=:bottomright,
407+
ylims=(1e-10, 1e5))
404408
plot!(richardson_no_preconditioner.history;
405409
label=L"$P = I$", lw=2, mark=:o)
406410
end
@@ -421,7 +425,7 @@ Clearly condition 2. suggests that the *perfect preconditioner* is $\mathbf{P} =
421425
i.e. we converge in a single Richardson step !
422426
The trouble of this choice is that step 2 of Algorithm 1 (Richardson iteration) now effectively requires to solve the system $\mathbf A \mathbf u^{(k)} = \mathbf r^{(k)}$ for $\mathbf u^{(k)}$, i.e. we are back to solving the original problem.
423427
424-
On the other hand condition 1. suggests to use $\mathbf P^{-1} = \mathbf I^{-1}$ (since the identity is cheapest to invert --- nothing needs to be done). However, this does not really do anything and does thus not improve the spectral radius.
428+
On the other hand condition 1. suggests to use $\mathbf P^{-1} = \mathbf I^{-1}$ (since the identity is cheapest to invert --- nothing needs to be done). However, this does not really do anything and does thus not reduce the value of $\|\mathbf{B}\|$. It will just be $\|\mathbf I - \mathbf A\|$.
425429
"""
426430

427431
# ╔═╡ a7ebacfb-b163-40aa-99c8-f5873478249b
@@ -923,7 +927,7 @@ takes us downhill (see green arrow). We thus propose an algorithm
923927
```math
924928
\tag{11}
925929
\begin{aligned}
926-
\phi(\textbf{x}^{(k+1)}) &= \phi(\textbf{x}^{(k)}) - \alpha_k \nabla \phi(\textbf{x}^{(k)}) \\&= \phi(\textbf{x}^{(k)}) + \alpha_k \textbf r^{(k)},
930+
\textbf{x}^{(k+1)} &= \textbf{x}^{(k)} - \alpha_k \nabla \phi(\textbf{x}^{(k)}) \\&= \textbf{x}^{(k)} + \alpha_k \textbf r^{(k)},
927931
\end{aligned}
928932
```
929933
where we used that $\nabla \phi(\textbf{x}^{(k)}) = - \textbf r^{(k)}$,
@@ -2686,6 +2690,7 @@ version = "1.4.1+2"
26862690
# ╟─6a5346df-6c21-47fb-9f99-d0bc75532135
26872691
# ╟─f2d4fbe9-e19a-41e0-9f3b-2f77ef0b12a7
26882692
# ╟─ef1ecb29-3ca0-4505-b96f-a56abd961979
2693+
# ╠═e277ff4c-87a8-440d-bba4-f30a20b47788
26892694
# ╠═54cb29d7-4933-4ab4-a3b5-26431d8432f9
26902695
# ╟─af630960-a734-4124-81d3-a2657456f6c2
26912696
# ╠═51030114-04d7-49eb-9ac1-042941681446

0 commit comments

Comments
 (0)