Skip to content

Commit fde5cfd

Browse files
committed
Small tweaks
1 parent f02d56a commit fde5cfd

File tree

1 file changed

+36
-27
lines changed

1 file changed

+36
-27
lines changed

src/06_Direct_methods.jl

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,11 @@ A_manual = Float64[ 2 1 0;
484484
# ╔═╡ 039b93ac-0a0e-45c3-acf9-70ec49b077c3
485485
md"""With this slider you can stop `factorise_lu` after 1, 2 or 3 steps, checking that agrees with the steps we computed manually:
486486
487-
- `nstep_lu_A = ` $(@bind nstep_lu_A Slider(1:3; default=1, show_value=true))
487+
- `nstep_lu_A = ` $(@bind nstep_lu_A Slider(0:3; default=0, show_value=true))
488488
"""
489489

490490
# ╔═╡ c918c14f-1532-4f40-9857-127554aaaf42
491-
let
491+
begin
492492
function factorise_lu_steps(A; nstep=size(A, 1))
493493
n = size(A, 1)
494494
L = zeros(n, n) # Initialise L and U by zeros
@@ -516,7 +516,7 @@ let
516516
return (; Aᵏ, L)
517517
end
518518

519-
(; Aᵏ, L) = factorise_lu_steps(A_manual; nstep=nstep_lu_A)
519+
factorise_lu_steps(A_manual; nstep=nstep_lu_A)
520520
end
521521

522522
# ╔═╡ 4da6a534-6a8f-464d-bbd4-9a6eec942688
@@ -624,34 +624,43 @@ Applying **Algorithm 4** the first step ($k=1$) will zero out the first column i
624624
```
625625
As a result the element `Aᵏ[k, k]` (for $k = 2$) is zero as marked \textcolor{red}{in red}. Continuing **Algorithm 4** for `k = 2` we would thus divide by zero
626626
in the statement $L_{ik} = \frac{A_{ik}^{(k)}}{A^{(k)}_{kk}}$
627-
--- which reflects above in the introduction of a `-Inf`
628-
in the matrix `L` that is returned by the algorithm:
627+
--- which in the introduction of a `-Inf`
628+
in the matrix `L` that is returned by the algorithm.
629+
630+
We run the algorithm step by step by advancing the slider:
631+
632+
- `nstep_lu_D = ` $(@bind nstep_lu_D Slider(0:3; default=0, show_value=true))
629633
"""
630634

631-
# ╔═╡ 0e403214-ddd3-4d3a-ae60-7b81951ab1b1
632-
let
633-
L, U = factorise_lu(D)
634-
L
635-
end
635+
# ╔═╡ 716a0a8d-2bf4-4e3d-8044-09d542152cdc
636+
factorise_lu_steps(D; nstep=nstep_lu_D)
636637

637-
# ╔═╡ 8e3d0734-bf9f-459d-87e4-07c50685bab1
638+
# ╔═╡ 9d5aab1f-3156-4c73-9e2f-b91f3ebe3984
638639
md"""
639-
From this point our computations are numerical garbage.
640+
We observe that from step $k=1$ and onwards our computations are numerical garbage.
641+
640642
Due their central role in the Gaussian elimination algorithm
641643
the elements $\left(A^{(k)}\right)_{kk}$
642644
--- respectively `Aᵏ[k, k]` in the implementation ---
643645
are usually referred to as **pivots**.
646+
"""
644647

645-
Notice that if instead of considering the matrix $A$ we consider the **permuted matrix**
648+
# ╔═╡ 58c13b75-006d-48e4-8ddf-290df272488b
649+
md"""
650+
If instead of considering the matrix $A$ we factorise the **permuted matrix**
646651
```math
647652
\mathbf{P}\mathbf{D} = \begin{pmatrix} 1 & 2 & 3\\
648653
\textcolor{orange}{7} &\textcolor{orange}{8} &\textcolor{orange}{9}\\
649654
\textcolor{blue}{2} & \textcolor{blue}{4} & \textcolor{blue}{5}
650655
\end{pmatrix}
651656
```
652-
which is the matrix `D` multiplied by the permutation matrix
657+
which is the matrix `D` in which the last two rows are swapped,
658+
the algorithm goes through as expected:
653659
"""
654660

661+
# ╔═╡ 49f66db0-3757-431d-85d7-4fe75096f9cc
662+
md"We remark that the permutation matrix $\mathbf P$ is given by ..."
663+
655664
# ╔═╡ 6f59c78d-7966-45ab-8b79-8443b82ba1df
656665
P = [1 0 0;
657666
0 0 1;
@@ -660,11 +669,6 @@ P = [1 0 0;
660669
# ╔═╡ a85a3ad2-a89d-4e7c-8275-a2f3cd2921b0
661670
P * D
662671

663-
# ╔═╡ 5bdda18b-cd8d-49f6-a107-ad58697eab52
664-
md"""
665-
the algorithm goes through and works as expected:
666-
"""
667-
668672
# ╔═╡ 0ea63086-f090-4b5b-a7d5-d6a1b21b1fd8
669673
let
670674
L, U = factorise_lu(P*D)
@@ -673,12 +677,15 @@ let
673677
@show L * U - P * D # show that L * U = P * D
674678
end;
675679

680+
# ╔═╡ 2d461a32-c40f-4670-9252-09baa5f3a6d5
681+
md"... and exactly achieves the task of swapping the last two rows, but leaving the rest of $\mathbf D$ intact as we saw above."
682+
676683
# ╔═╡ c42c3c63-b96c-4af0-a276-72ebd96fe23c
677684
md"""
678-
That is we obtain a factorisation $\mathbf{L} \mathbf{U} = \mathbf{P} \mathbf{D}$ into lower-triangular $\mathbf L$ and upper-triangular $\mathbf U$,
679-
just not of the original matrix $\mathbf D$, but a permuted form.
685+
We notice that even though $\mathbf D$ cannot be permuted it is possible to obtain an LU factorisation $\mathbf{L} \mathbf{U} = \mathbf{P} \mathbf{D}$
686+
if we additionally allow the freedom to cleverly permute the rows of $\mathbf D$.
680687
681-
This result is in fact rather general:
688+
This is in fact a general result:
682689
683690
!!! info "Theorem 1"
684691
Every non-singular matrix $\textbf A \in \mathbb{R}^{n\times n}$ admits a factorisation
@@ -692,7 +699,7 @@ This result is in fact rather general:
692699
# ╔═╡ d85ab4d1-730b-4a6e-bd4d-46e450261f64
693700
md"""
694701
That is to say, that while in general **factorising a matrix $\mathbf A$ can fail**,
695-
it always suceeds for non-singular matrices if we give ourselves the freedom to permute the rows of $\mathbf A$.
702+
**it always suceeds** for non-singular matrices if we **give ourselves the freedom to permute the rows** of $\mathbf A$.
696703
697704
Finding a suitable $\mathbf P$ can be achieved by a small
698705
modification of **Algorithm 4**.
@@ -2273,12 +2280,14 @@ version = "17.4.0+2"
22732280
# ╟─8c0d6843-6bde-4c14-8a98-6cf7cb9f244a
22742281
# ╟─2baa3355-f51b-464e-a55a-3471fb7e0100
22752282
# ╟─7bece62a-5da4-4a4c-9da8-dfcb797fb27a
2276-
# ╠═0e403214-ddd3-4d3a-ae60-7b81951ab1b1
2277-
# ╟─8e3d0734-bf9f-459d-87e4-07c50685bab1
2278-
# ╠═6f59c78d-7966-45ab-8b79-8443b82ba1df
2283+
# ╟─716a0a8d-2bf4-4e3d-8044-09d542152cdc
2284+
# ╟─9d5aab1f-3156-4c73-9e2f-b91f3ebe3984
2285+
# ╟─58c13b75-006d-48e4-8ddf-290df272488b
22792286
# ╠═a85a3ad2-a89d-4e7c-8275-a2f3cd2921b0
2280-
# ╟─5bdda18b-cd8d-49f6-a107-ad58697eab52
22812287
# ╠═0ea63086-f090-4b5b-a7d5-d6a1b21b1fd8
2288+
# ╟─49f66db0-3757-431d-85d7-4fe75096f9cc
2289+
# ╠═6f59c78d-7966-45ab-8b79-8443b82ba1df
2290+
# ╟─2d461a32-c40f-4670-9252-09baa5f3a6d5
22822291
# ╟─c42c3c63-b96c-4af0-a276-72ebd96fe23c
22832292
# ╟─d85ab4d1-730b-4a6e-bd4d-46e450261f64
22842293
# ╠═0de87398-22d4-4ba6-8831-bcf30e67a6db

0 commit comments

Comments
 (0)