/ tutorials / laplace-dirichlet
Sign in
tutorials / laplace-dirichlet
laplace-dirichlet / src / chapters / ch03 / chapter.ts
52 lines · 1.8 KBCodeBlameHistory
088be4cAn interactive tutorial on the Dirichlet problem, accuracy against costJeremy Magland 1import { createElement, Fragment } from 'react'
2import type { Chapter } from '../../ui/types.ts'
3import driver from '../onedim/driver.m?raw'
4import script from './highorder.m?raw'
5import text from './text.md?raw'
6import { Convergence, WorkPrecision, fmtErr, type SweepOut } from '../onedim/panels.tsx'
7import { KIND_CONTROL } from '../shared.ts'
9const NS = [16, 64, 256, 1024, 4096, 16384]
11export const ch03: Chapter = {
12 id: 'higher-order',
13 nav: 'Two more orders, almost free',
14 part: 'One dimension',
15 title: 'Two more orders, almost free',
16 blurb: 'The compact fourth-order scheme, and how to read a work-precision diagram.',
17 text,
18 labs: [
19 {
20 id: 'orders',
21 title: 'Second order against fourth',
22 caption:
23 'Both schemes solve the same tridiagonal system; only the right-hand side differs. The second figure is the one that decides anything.',
24 driver,
25 script,
26 editorOpen: true,
27 controls: [KIND_CONTROL],
28 defaults: { kind: 'smooth', mode: 'sweep', ns: NS, nmaxs: [16384, 16384], timed: 1 },
29 render: (d: SweepOut) =>
30 createElement(
31 Fragment,
32 null,
33 createElement(Convergence, {
34 key: 'c',
35 data: d,
36 style: {
37 slots: ['fd2', 'fd4'],
38 refs: [
39 { p: -2, label: 'slope −2' },
40 { p: -4, label: 'slope −4' },
41 ],
42 },
43 }),
44 createElement(WorkPrecision, { key: 'w', data: d, style: { slots: ['fd2', 'fd4'] } }),
45 ),
46 summary: (d: SweepOut) => [
47 { label: 'best 2nd order', value: fmtErr(Math.min(...(d.E[0].filter((v) => v != null) as number[]))) },
48 { label: 'best 4th order', value: fmtErr(Math.min(...(d.E[1].filter((v) => v != null) as number[]))) },
49 ],
50 },
51 ],
↑↓ move↵openescclose