|
1 | 1 | ### A Pluto.jl notebook ###
|
2 |
| -# v0.20.5 |
| 2 | +# v0.20.6 |
3 | 3 |
|
4 | 4 | using Markdown
|
5 | 5 | using InteractiveUtils
|
|
68 | 68 | """
|
69 | 69 |
|
70 | 70 | # ╔═╡ 93b28014-c767-4f40-b27c-4646f63faa89
|
71 |
| -RobustLocalResource("https://raw.githubusercontent.com/epfl-matmat/numerical-analysis/master/notes/img/node-doubling.svg", "img/heat-equation.svg", :width => 500) |
| 71 | +RobustLocalResource("https://raw.githubusercontent.com/epfl-matmat/numerical-analysis/30a76271c3fa3be9d24896ecd2450d18fa505df3/src/img/heat-equation.svg", "img/heat-equation.svg", :width => 500) |
72 | 72 |
|
73 | 73 | # ╔═╡ f1b662de-b4cf-4a73-9c00-580a2ea8a428
|
74 | 74 | md"""
|
@@ -180,7 +180,7 @@ Similar to our approach when [solving initial value problems (chapter 11)](https
|
180 | 180 | we **divide the full interval $[0, L]$ into $N+1$ subintervals** $[x_j, x_{j+1}]$
|
181 | 181 | of uniform size $h$, i.e.
|
182 | 182 | ```math
|
183 |
| -x_j = j\, h \quad j = 0, \ldots, N, \qquad h = \frac{L}{N+1}. |
| 183 | +x_j = j\, h \quad j = 0, \ldots, N+1, \qquad h = \frac{L}{N+1}. |
184 | 184 | ```
|
185 | 185 | Our goal is thus to find approximate points $u_j$ such that $u_j ≈ u(x_j)$ at the nodes $x_j$.
|
186 | 186 | """
|
@@ -762,7 +762,7 @@ The original problem (17) is additionally called the **strong form** of the heat
|
762 | 762 | !!! info "Observation: Strong and weak solutions"
|
763 | 763 | If $u$ is a solution to the strong form (17) of a BVP,
|
764 | 764 | than it is also a solution to the weak form (19).
|
765 |
| - However, **not every weak solution as also a strong solution**. |
| 765 | + However, **not every weak solution is also a strong solution**. |
766 | 766 | """
|
767 | 767 |
|
768 | 768 | # ╔═╡ 79816267-531b-4b99-bdea-1194574dd160
|
@@ -1070,22 +1070,42 @@ end
|
1070 | 1070 | md"""We see that already for 5 $\sin$ basis functions it becomes visually very hard to see the difference to the reference solution with $300$ basis functions.
|
1071 | 1071 |
|
1072 | 1072 | Numerically we observe a **quadratic convergence** in a log-log plot:
|
| 1073 | +
|
| 1074 | +- Show finite difference approximation of same size ($N = m$) $(@bind show_fd CheckBox(; default=false)) |
1073 | 1075 | """
|
1074 | 1076 |
|
1075 | 1077 | # ╔═╡ 1d55c98e-4ed9-4ac4-a847-b18432483472
|
1076 | 1078 | let
|
1077 | 1079 | x = range(0, π; length=1000)
|
1078 |
| - reference(x) = sine_solution(300, x) |
| 1080 | + reference(x) = sine_solution(800, x) |
1079 | 1081 |
|
1080 |
| - ms = [5, 10, 20, 40, 50, 60, 80, 100] |
| 1082 | + ms = [5, 10, 20, 40, 50, 60, 80, 100, 300] |
1081 | 1083 | errors = Float64[]
|
1082 | 1084 | for m in ms
|
1083 | 1085 | error = [abs(sine_solution(m, xᵢ) - reference(xᵢ)) for xᵢ in x]
|
1084 | 1086 | push!(errors, maximum(error))
|
1085 | 1087 | end
|
1086 | 1088 |
|
1087 |
| - p = plot(ms, errors, yaxis=:log, xaxis=:log, lw=2, mark=:o, title=L"Convergence in $m$", xlabel=L"m", ylabel="maximal error", label="Error") |
| 1089 | + p = plot(ms, errors, yaxis=:log, xaxis=:log, lw=2, mark=:o, title=L"Convergence in $m$", xlabel=L"m", ylabel="maximal error", label="Error sin Galerkin") |
1088 | 1090 | plot!(p, ms, 1 ./ms.^2, ls=:dash, lw=2, label=L"O(m^2)")
|
| 1091 | + |
| 1092 | + ylims!(p, (1e-6, 1e-1)) |
| 1093 | + xticks!(p, 10.0 .^ (0:0.5:3)) |
| 1094 | + yticks!(p, 10.0 .^ (0:-1:-6)) |
| 1095 | + |
| 1096 | + if show_fd |
| 1097 | + errors_fd = Float64[] |
| 1098 | + for N in ms |
| 1099 | + res_fd = fd_dirichlet(f, L, α, β, N) |
| 1100 | + x = res_fd.x |
| 1101 | + u = res_fd.u |
| 1102 | + error = [ u_exact(x[j]) - u[j] for j in 1:length(x)] |
| 1103 | + push!(errors_fd, maximum(error)) |
| 1104 | + end |
| 1105 | + plot!(p, ms, errors_fd; lw=2, mark=:o, c=3, label="Error finite-differences") |
| 1106 | + end |
| 1107 | + |
| 1108 | + p |
1089 | 1109 | end
|
1090 | 1110 |
|
1091 | 1111 | # ╔═╡ 3348115a-2fd4-4935-9dba-b85d9e0c95f5
|
@@ -1118,7 +1138,7 @@ PlutoUI = "~0.7.59"
|
1118 | 1138 | PLUTO_MANIFEST_TOML_CONTENTS = """
|
1119 | 1139 | # This file is machine-generated - editing it directly is not advised
|
1120 | 1140 |
|
1121 |
| -julia_version = "1.11.4" |
| 1141 | +julia_version = "1.11.5" |
1122 | 1142 | manifest_format = "2.0"
|
1123 | 1143 | project_hash = "386992f2ee9496aea372b754edcbbad6c546e5b7"
|
1124 | 1144 |
|
@@ -1659,7 +1679,7 @@ version = "0.3.27+1"
|
1659 | 1679 | [[deps.OpenLibm_jll]]
|
1660 | 1680 | deps = ["Artifacts", "Libdl"]
|
1661 | 1681 | uuid = "05823500-19ac-5b8b-9628-191a04bc5112"
|
1662 |
| -version = "0.8.1+4" |
| 1682 | +version = "0.8.5+0" |
1663 | 1683 |
|
1664 | 1684 | [[deps.OpenSSL]]
|
1665 | 1685 | deps = ["BitFlags", "Dates", "MozillaCACerts_jll", "OpenSSL_jll", "Sockets"]
|
@@ -2376,7 +2396,7 @@ version = "1.4.1+2"
|
2376 | 2396 | # ╟─d0a2133c-47d0-40d5-8508-18bb046d92d1
|
2377 | 2397 | # ╟─aa589aa5-1a5c-4782-af66-2509f21ac891
|
2378 | 2398 | # ╟─4fee47fc-077d-4921-8572-7820ab84988e
|
2379 |
| -# ╟─1d55c98e-4ed9-4ac4-a847-b18432483472 |
| 2399 | +# ╠═1d55c98e-4ed9-4ac4-a847-b18432483472 |
2380 | 2400 | # ╟─3348115a-2fd4-4935-9dba-b85d9e0c95f5
|
2381 | 2401 | # ╟─00000000-0000-0000-0000-000000000001
|
2382 | 2402 | # ╟─00000000-0000-0000-0000-000000000002
|
0 commit comments