Skip to content

Commit c65b8c7

Browse files
committed
Post-lecture updates
1 parent 5c61941 commit c65b8c7

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

src/06_Direct_methods.jl

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
### A Pluto.jl notebook ###
2-
# v0.20.4
2+
# v0.20.5
33

44
using Markdown
55
using InteractiveUtils
66

77
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
88
macro bind(def, element)
99
#! format: off
10-
quote
10+
return quote
1111
local iv = try Base.loaded_modules[Base.PkgId(Base.UUID("6e696c72-6542-2067-7265-42206c756150"), "AbstractPlutoDingetjes")].Bonds.initial_value catch; b -> missing; end
1212
local el = $(esc(element))
1313
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : iv(el)
@@ -1277,7 +1277,7 @@ md"""
12771277
| type of $n\times n$ matrix | memory usage | comment |
12781278
| ------------------------- | ------------ | ------------ |
12791279
| full matrix | $O(n^2)$ |
1280-
| general sparse matrix | $O(n^2)$ | fill-in
1280+
| general sparse matrix | $O(n)$ | fill-in
12811281
| banded matrix, band width $d$ | $O(n\,d)$ | stays block-diagonal
12821282
12831283
"""
@@ -1376,16 +1376,21 @@ For this course if you are asked to determine the asymptotic complexity,
13761376
you will not asked to deal with these details. For our problems it will be sufficient to only look at the most deeply nested loop and ignore the rest of the code as part of a complexity analysis.
13771377
""")
13781378

1379-
# ╔═╡ 5d8d4e66-20a0-41d9-8aeb-faa7d56628f9
1379+
# ╔═╡ 334d83a2-4809-4e85-808f-1213a56be9b7
13801380
md"""
13811381
!!! info "Overview of computational cost"
13821382
For vectors $\textbf v, \textbf w \in \mathbb{R}^n$ and matrices $\mathbf A \in \mathbb R^{n\times n}$ the computational cost is
13831383
13841384
| operation | cost |
13851385
| ------------------------- | ------------ |
1386-
| dot product $\mathbf v ^T \mathbf w$ | $O(n^2)$ |
1387-
| MatVec $\mathbf A \mathbf v$ | $O(n^3)$
1386+
| dot product $\mathbf v ^T \mathbf w$ | $O(n)$ |
1387+
| matriv-vector product $\mathbf A \mathbf v$ | $O(n^2)$
1388+
| matrix-matrix multiplication $\mathbf A \mathbf B$ | $O(n^3)$
13881389
1390+
"""
1391+
1392+
# ╔═╡ 3de7544d-a5e2-43fc-9af0-d2e37386b72a
1393+
md"""
13891394
Finally a few rough guidelines:
13901395
13911396
!!! info "General guideline to estimate computational cost"
@@ -1395,6 +1400,22 @@ Finally a few rough guidelines:
13951400
4. Multiply the result of 2. and all index ranges of 3 to get the total scaling. Typically for a single loop nesting the cost is $O(n)$ for a doubly nested loop $O(n^2)$ and so on.
13961401
"""
13971402

1403+
# ╔═╡ 7afabc20-a2a8-4b6d-87f8-09b84206a6dd
1404+
md"""
1405+
!!! warning "Example Matrix-matrix multiplication"
1406+
Let us code up an algorithm how to compute the product of two matrices
1407+
$\mathbf A, \mathbf B \in \mathbb{R}^{n\times n}$ and analyse its complexity.
1408+
"""
1409+
1410+
# ╔═╡ 1863e20c-ef35-4cea-8d3c-a33a0a42fc2e
1411+
function matmul(A, B)
1412+
C = zeros(size(A, 1), size(B, 2))
1413+
1414+
# loops ...
1415+
1416+
C
1417+
end
1418+
13981419
# ╔═╡ 2d98da64-481b-4e86-9daa-f199294ed417
13991420
md"""
14001421
### LU factorisation
@@ -2454,7 +2475,10 @@ version = "17.4.0+2"
24542475
# ╠═0f8b23ab-c797-4513-b70c-5827376f6093
24552476
# ╟─756a5787-6f64-4308-b879-da7676d39a8c
24562477
# ╟─01a66e18-bc56-4204-b4b8-9bf46155aec1
2457-
# ╟─5d8d4e66-20a0-41d9-8aeb-faa7d56628f9
2478+
# ╟─334d83a2-4809-4e85-808f-1213a56be9b7
2479+
# ╟─3de7544d-a5e2-43fc-9af0-d2e37386b72a
2480+
# ╟─7afabc20-a2a8-4b6d-87f8-09b84206a6dd
2481+
# ╠═1863e20c-ef35-4cea-8d3c-a33a0a42fc2e
24582482
# ╟─2d98da64-481b-4e86-9daa-f199294ed417
24592483
# ╟─41ebce0a-1fde-4704-b889-b1a8391ccac7
24602484
# ╟─c34c30e8-b777-43b7-aae6-cd88d7179015

0 commit comments

Comments
 (0)