Skip to content

Commit 20c7184

Browse files
committed
polishing module 1 lectures
1 parent f7a27aa commit 20c7184

File tree

8 files changed

+856
-1086
lines changed

8 files changed

+856
-1086
lines changed

src/images_abstractions/dynamicprograms.jl

Lines changed: 182 additions & 138 deletions
Large diffs are not rendered by default.

src/images_abstractions/images.jl

Lines changed: 98 additions & 403 deletions
Large diffs are not rendered by default.

src/images_abstractions/newton_method.jl

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
### A Pluto.jl notebook ###
2-
# v0.19.14
2+
# v0.19.25
33

44
#> [frontmatter]
55
#> chapter = 1
@@ -82,13 +82,6 @@ md"""
8282
x₀ = $(@bind x02 Slider(-10:10, show_value=true, default=6))
8383
"""
8484

85-
# ╔═╡ ecb40aea-7b9c-11eb-1476-e54faf32d91c
86-
let
87-
f(x) = x^2 - 2
88-
89-
standard_Newton(f, n2, -1:0.01:10, x02, -10, 70)
90-
end
91-
9285
# ╔═╡ 2445da24-7b9d-11eb-02bd-eb99a3d95a2e
9386
md"""
9487
n = $(@bind n Slider(0:10, show_value=true, default=0))
@@ -99,13 +92,6 @@ md"""
9992
x₀ = $(@bind x0 Slider(-10:10, show_value=true, default=6))
10093
"""
10194

102-
# ╔═╡ ec6c6328-7b9c-11eb-1c69-dba12ae522ad
103-
let
104-
f(x) = 0.2x^3 - 4x + 1
105-
106-
standard_Newton(f, n, -10:0.01:10, x0, -10, 70)
107-
end
108-
10995
# ╔═╡ c0b4defe-7c2f-11eb-1913-bdb01d28a4a8
11096
md"""
11197
## Using symbolic calculations to understand derivatives and nonlinear maps
@@ -121,26 +107,23 @@ Let's see what happens if we perturb a function $f$ around a point $z$ by a smal
121107
# ╔═╡ 71efd6b0-7c30-11eb-0da7-0d4a5ab8f8ff
122108
@variables z, η
123109

110+
# ╔═╡ a869e6c6-7c31-11eb-13c8-155d08be02eb
111+
md"""
112+
m = $(@bind m Slider(1:6, show_value=true))
113+
"""
114+
124115
# ╔═╡ 6dc89964-7c30-11eb-0a41-8d97b210ed34
125116
f(x) = x^m - 2;
126117

127118
# ╔═╡ d35e0cc8-7c30-11eb-28d3-17c9e221ea62
128119
f′(x) = ForwardDiff.derivative(f, x);
129120

130-
# ╔═╡ a869e6c6-7c31-11eb-13c8-155d08be02eb
131-
md"""
132-
m = $(@bind m Slider(1:6, show_value=true))
133-
"""
134-
135121
# ╔═╡ 63dbf052-7c32-11eb-1062-5b3581d38f70
136122
f(z)
137123

138124
# ╔═╡ 9371f930-7c30-11eb-1f77-c7f31b97ea26
139125
f(z + η)
140126

141-
# ╔═╡ 98158a38-7c30-11eb-0796-2335e97ec6d0
142-
expand( f(z + η) )
143-
144127
# ╔═╡ 9d778e36-7c30-11eb-1f4b-894af86a8f5d
145128
md"""
146129
When $\eta$ is small, $\eta^2$ is *very* small, so we can ignore it. We are left with terms that either don't contain $\eta$ (constants), or multiply $\eta$ (linear). The part that multiplies $\eta$ is the derivative:
@@ -152,9 +135,6 @@ f′(z)
152135
# ╔═╡ ea741018-7c30-11eb-3912-a50475e6ec49
153136
f(z) + η*f′(z)
154137

155-
# ╔═╡ e18f2470-7c31-11eb-2b74-d59d00d20ba4
156-
expand( f(z + η) ) - ( f(z) + η*f′(z) )
157-
158138
# ╔═╡ 389e990e-7c40-11eb-37c4-5ba0f59173b3
159139
md"""
160140
The derivative gives the "*linear* part" of the function. `ForwardDiff.jl`, and forward-mode automatic differentiation in general, effectively uses this (although not symbolically in this sense) to just propagate the linear part of each function through a calculation.
@@ -259,21 +239,6 @@ p = $(@bind p Slider(0:0.01:1, show_value=true))
259239
# ╔═╡ 23536420-7c2d-11eb-20b0-9523f7a5f9d7
260240
@variables a, b, δ, ϵ
261241

262-
# ╔═╡ 3828b94c-7c2d-11eb-2e01-79038b0f5226
263-
image = expand.(T(p)( [ (a + δ), (b + ϵ) ] ))
264-
265-
# ╔═╡ 09b97be8-7c2e-11eb-05fd-65bbd097afb8
266-
jacobian(T(p), [a, b]) .|> Text
267-
268-
# ╔═╡ 18ce2fac-7c2e-11eb-03d2-b3a674621662
269-
jacobian(T(p), [a, b]) * [δ, ϵ]
270-
271-
# ╔═╡ ed605b90-7c3e-11eb-34e9-776a05a177dd
272-
image - T(p)([a, b])
273-
274-
# ╔═╡ 35b5c5c6-7c3f-11eb-2723-4b406a809114
275-
simplify.(expand.(image - T(p)([a, b]) - jacobian(T(p), [a, b]) * [δ, ϵ]))
276-
277242
# ╔═╡ 4dd2322c-7ba0-11eb-2b3b-af7c6c1d60a0
278243
md"""
279244
## Newton for transformations in 2 dimensions
@@ -394,9 +359,29 @@ function standard_Newton(f, n, x_range, x0, ymin=-10, ymax=10)
394359

395360
end
396361

362+
# ╔═╡ ecb40aea-7b9c-11eb-1476-e54faf32d91c
363+
let
364+
f(x) = x^2 - 2
365+
366+
standard_Newton(f, n2, -1:0.01:10, x02, -10, 70)
367+
end
368+
369+
# ╔═╡ ec6c6328-7b9c-11eb-1c69-dba12ae522ad
370+
let
371+
f(x) = 0.2x^3 - 4x + 1
372+
373+
standard_Newton(f, n, -10:0.01:10, x0, -10, 70)
374+
end
375+
397376
# ╔═╡ 515c23b6-7c2d-11eb-28c9-1b1d92eb4ba0
398377
T(α) = ((x, y),) -> [x + α*y^2, y + α*x^2]
399378

379+
# ╔═╡ 09b97be8-7c2e-11eb-05fd-65bbd097afb8
380+
jacobian(T(p), [a, b]) .|> Text
381+
382+
# ╔═╡ 18ce2fac-7c2e-11eb-03d2-b3a674621662
383+
jacobian(T(p), [a, b]) * [δ, ϵ]
384+
400385
# ╔═╡ 395fd8e2-7c31-11eb-1933-dd719fa0cd22
401386
md"""
402387
α = $(@bind α Slider(0.0:0.01:1.0, show_value=true))
@@ -419,6 +404,21 @@ md"""
419404
# ╔═╡ 786f8e78-7c2d-11eb-1bb8-c5cb2e349f45
420405
expand(ex) = simplify(ex, polynorm=true)
421406

407+
# ╔═╡ 98158a38-7c30-11eb-0796-2335e97ec6d0
408+
expand( f(z + η) )
409+
410+
# ╔═╡ e18f2470-7c31-11eb-2b74-d59d00d20ba4
411+
expand( f(z + η) ) - ( f(z) + η*f′(z) )
412+
413+
# ╔═╡ 3828b94c-7c2d-11eb-2e01-79038b0f5226
414+
image = expand.(T(p)( [ (a + δ), (b + ϵ) ] ))
415+
416+
# ╔═╡ ed605b90-7c3e-11eb-34e9-776a05a177dd
417+
image - T(p)([a, b])
418+
419+
# ╔═╡ 35b5c5c6-7c3f-11eb-2723-4b406a809114
420+
simplify.(expand.(image - T(p)([a, b]) - jacobian(T(p), [a, b]) * [δ, ϵ]))
421+
422422
# ╔═╡ 00000000-0000-0000-0000-000000000001
423423
PLUTO_PROJECT_TOML_CONTENTS = """
424424
[deps]
@@ -535,7 +535,7 @@ uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
535535
version = "1.0.8+0"
536536
537537
[[Cairo_jll]]
538-
deps = ["Artifacts", "Bzip2_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
538+
deps = ["Artifacts", "Bzip2_jll", "CompilerSupportLibraries_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
539539
git-tree-sha1 = "4b859a208b2397a7a623a03449e4636bdb17bcf2"
540540
uuid = "83423d85-b0ee-5818-9007-b63ccbeb887a"
541541
version = "1.16.1+1"
@@ -613,7 +613,7 @@ version = "4.3.0"
613613
[[CompilerSupportLibraries_jll]]
614614
deps = ["Artifacts", "Libdl"]
615615
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
616-
version = "0.5.2+0"
616+
version = "1.0.1+0"
617617
618618
[[CompositeTypes]]
619619
git-tree-sha1 = "02d2316b7ffceff992f3096ae48c7829a8aa0638"
@@ -842,9 +842,9 @@ version = "0.21.0+0"
842842
843843
[[Glib_jll]]
844844
deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE2_jll", "Pkg", "Zlib_jll"]
845-
git-tree-sha1 = "fb83fbe02fe57f2c068013aa94bcdf6760d3a7a7"
845+
git-tree-sha1 = "d3b3624125c1474292d0d8ed0f65554ac37ddb23"
846846
uuid = "7746bdde-850d-59dc-9ae8-88ece973131d"
847-
version = "2.74.0+1"
847+
version = "2.74.0+2"
848848
849849
[[Graphite2_jll]]
850850
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
@@ -1052,9 +1052,9 @@ version = "1.42.0+0"
10521052
10531053
[[Libiconv_jll]]
10541054
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
1055-
git-tree-sha1 = "42b62845d70a619f063a7da093d995ec8e15e778"
1055+
git-tree-sha1 = "c7cb1f5d892775ba13767a87c7ada0b980ea0a71"
10561056
uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531"
1057-
version = "1.16.1+1"
1057+
version = "1.16.1+2"
10581058
10591059
[[Libmount_jll]]
10601060
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
@@ -1298,9 +1298,9 @@ uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
12981298
12991299
[[Qt5Base_jll]]
13001300
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Fontconfig_jll", "Glib_jll", "JLLWrappers", "Libdl", "Libglvnd_jll", "OpenSSL_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libxcb_jll", "Xorg_xcb_util_image_jll", "Xorg_xcb_util_keysyms_jll", "Xorg_xcb_util_renderutil_jll", "Xorg_xcb_util_wm_jll", "Zlib_jll", "xkbcommon_jll"]
1301-
git-tree-sha1 = "c6c0f690d0cc7caddb74cef7aa847b824a16b256"
1301+
git-tree-sha1 = "0c03844e2231e12fda4d0086fd7cbe4098ee8dc5"
13021302
uuid = "ea2cea3b-5b76-57ae-a6ef-0a8af62496e1"
1303-
version = "5.15.3+1"
1303+
version = "5.15.3+2"
13041304
13051305
[[QuadGK]]
13061306
deps = ["DataStructures", "LinearAlgebra"]
@@ -1522,7 +1522,7 @@ version = "1.10.0"
15221522
[[Tar]]
15231523
deps = ["ArgTools", "SHA"]
15241524
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
1525-
version = "1.10.0"
1525+
version = "1.10.1"
15261526
15271527
[[TensorCore]]
15281528
deps = ["LinearAlgebra"]

0 commit comments

Comments
 (0)