Skip to content

Commit 7990c18

Browse files
committed
Rewire DGF/Stationary sequencing
1 parent 89a0dc8 commit 7990c18

4 files changed

Lines changed: 252 additions & 54 deletions

cleared-demos/pdes/Discrete Greens Functions and Interaction Rank.ipynb

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
{
3535
"cell_type": "code",
36-
"execution_count": 2,
36+
"execution_count": 3,
3737
"id": "50cb54b8-95ae-4b38-a34b-3b68d9251ea5",
3838
"metadata": {},
3939
"outputs": [],
@@ -44,9 +44,17 @@
4444
"import matplotlib.pyplot as pt"
4545
]
4646
},
47+
{
48+
"cell_type": "markdown",
49+
"id": "d7ccce38-d1e2-483f-b811-ca580f36317e",
50+
"metadata": {},
51+
"source": [
52+
"Let's solve $u''=-30x^2$ with $u(0)=1$ and $u(1)=-1$."
53+
]
54+
},
4755
{
4856
"cell_type": "code",
49-
"execution_count": 3,
57+
"execution_count": 5,
5058
"id": "1f92e1b9-6975-458b-861c-64a7044e0c07",
5159
"metadata": {},
5260
"outputs": [],
@@ -57,18 +65,69 @@
5765
"h = mesh[1] - mesh[0]"
5866
]
5967
},
68+
{
69+
"cell_type": "markdown",
70+
"id": "972fef0b-fdf2-4709-b7bb-151573e1f583",
71+
"metadata": {},
72+
"source": [
73+
"Set up the system matrix `A` to carry out centered finite differences\n",
74+
"\n",
75+
"$$\n",
76+
"u''(x)\\approx \\frac{u(x+h) - 2u(x) + u(x-h)}{h^2}.\n",
77+
"$$\n",
78+
"\n",
79+
"Use `np.eye(n, k=...)`. What needs to be in the first and last row?"
80+
]
81+
},
6082
{
6183
"cell_type": "code",
62-
"execution_count": 4,
84+
"execution_count": 6,
6385
"id": "0865715a-b5c7-4cd6-9a85-ce751c158d29",
6486
"metadata": {},
6587
"outputs": [],
88+
"source": []
89+
},
90+
{
91+
"cell_type": "markdown",
92+
"id": "80bf4822-86e1-4948-b801-43ea6f5598f2",
93+
"metadata": {},
94+
"source": [
95+
"Next, fix the right hand side: "
96+
]
97+
},
98+
{
99+
"cell_type": "code",
100+
"execution_count": 7,
101+
"id": "a246c2c3-79ac-4966-9d46-34b6493eb16d",
102+
"metadata": {},
103+
"outputs": [],
104+
"source": []
105+
},
106+
{
107+
"cell_type": "markdown",
108+
"id": "de5fe2de-537e-42a3-9415-4998a11699d6",
109+
"metadata": {},
110+
"source": [
111+
"Compute a reference solution `x_true` to the linear system:"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": 8,
117+
"id": "de331c55-d62b-4edc-91de-79181e35342b",
118+
"metadata": {},
119+
"outputs": [],
120+
"source": [
121+
"x_true = la.solve(A, b)\n",
122+
"pt.plot(mesh, x_true)"
123+
]
124+
},
125+
{
126+
"cell_type": "markdown",
127+
"id": "2d3e09f9-f508-4752-b3f6-4847d3fd3ad8",
128+
"metadata": {},
66129
"source": [
67-
"A = (np.eye(n, k=1) + -2*np.eye(n) + np.eye(n, k=-1))/h**2\n",
68-
"A[0] = 0\n",
69-
"A[-1] = 0\n",
70-
"A[0,0] = 1\n",
71-
"A[-1,-1] = 1"
130+
"Next, let's consider the influence of each individual RHS component:"
72131
]
73132
},
74133
{

cleared-demos/pdes/Stationary Iterative Methods.ipynb

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
{
3434
"cell_type": "code",
35-
"execution_count": 2,
35+
"execution_count": 3,
3636
"metadata": {
3737
"collapsed": false,
3838
"jupyter": {
@@ -56,7 +56,7 @@
5656
},
5757
{
5858
"cell_type": "code",
59-
"execution_count": 3,
59+
"execution_count": 4,
6060
"metadata": {
6161
"collapsed": false,
6262
"jupyter": {
@@ -94,7 +94,13 @@
9494
}
9595
},
9696
"outputs": [],
97-
"source": []
97+
"source": [
98+
"A = (np.eye(n, k=1) + -2*np.eye(n) + np.eye(n, k=-1))/h**2\n",
99+
"A[0] = 0\n",
100+
"A[-1] = 0\n",
101+
"A[0,0] = 1\n",
102+
"A[-1,-1] = 1"
103+
]
98104
},
99105
{
100106
"cell_type": "markdown",
@@ -105,7 +111,7 @@
105111
},
106112
{
107113
"cell_type": "code",
108-
"execution_count": 9,
114+
"execution_count": 6,
109115
"metadata": {
110116
"collapsed": false,
111117
"jupyter": {
@@ -128,7 +134,7 @@
128134
},
129135
{
130136
"cell_type": "code",
131-
"execution_count": 10,
137+
"execution_count": 7,
132138
"metadata": {
133139
"collapsed": false,
134140
"jupyter": {
@@ -157,7 +163,7 @@
157163
},
158164
{
159165
"cell_type": "code",
160-
"execution_count": 44,
166+
"execution_count": 8,
161167
"metadata": {
162168
"collapsed": false,
163169
"jupyter": {
@@ -178,7 +184,7 @@
178184
},
179185
{
180186
"cell_type": "code",
181-
"execution_count": 42,
187+
"execution_count": 9,
182188
"metadata": {
183189
"collapsed": false,
184190
"jupyter": {
@@ -202,7 +208,7 @@
202208
},
203209
{
204210
"cell_type": "code",
205-
"execution_count": 43,
211+
"execution_count": 10,
206212
"metadata": {
207213
"collapsed": false,
208214
"jupyter": {
@@ -233,7 +239,7 @@
233239
},
234240
{
235241
"cell_type": "code",
236-
"execution_count": 45,
242+
"execution_count": 12,
237243
"metadata": {
238244
"collapsed": false,
239245
"jupyter": {
@@ -247,7 +253,7 @@
247253
},
248254
{
249255
"cell_type": "code",
250-
"execution_count": 64,
256+
"execution_count": 56,
251257
"metadata": {
252258
"collapsed": false,
253259
"jupyter": {
@@ -282,7 +288,7 @@
282288
},
283289
{
284290
"cell_type": "code",
285-
"execution_count": 92,
291+
"execution_count": 174,
286292
"metadata": {
287293
"collapsed": false,
288294
"jupyter": {
@@ -296,7 +302,7 @@
296302
},
297303
{
298304
"cell_type": "code",
299-
"execution_count": 106,
305+
"execution_count": 240,
300306
"metadata": {
301307
"collapsed": false,
302308
"jupyter": {
@@ -337,11 +343,32 @@
337343
},
338344
"outputs": [],
339345
"source": []
346+
},
347+
{
348+
"cell_type": "code",
349+
"execution_count": null,
350+
"metadata": {},
351+
"outputs": [],
352+
"source": []
353+
},
354+
{
355+
"cell_type": "code",
356+
"execution_count": null,
357+
"metadata": {},
358+
"outputs": [],
359+
"source": []
360+
},
361+
{
362+
"cell_type": "code",
363+
"execution_count": null,
364+
"metadata": {},
365+
"outputs": [],
366+
"source": []
340367
}
341368
],
342369
"metadata": {
343370
"kernelspec": {
344-
"display_name": "Python 3",
371+
"display_name": "Python 3 (ipykernel)",
345372
"language": "python",
346373
"name": "python3"
347374
},
@@ -355,7 +382,7 @@
355382
"name": "python",
356383
"nbconvert_exporter": "python",
357384
"pygments_lexer": "ipython3",
358-
"version": "3.8.3"
385+
"version": "3.14.3"
359386
}
360387
},
361388
"nbformat": 4,

0 commit comments

Comments
 (0)