import { createElement, Fragment } from 'react' import type { Chapter } from '../../ui/types.ts' import driver from '../onedim/driver.m?raw' import script from './highorder.m?raw' import text from './text.md?raw' import { Convergence, WorkPrecision, fmtErr, type SweepOut } from '../onedim/panels.tsx' import { KIND_CONTROL } from '../shared.ts' const NS = [16, 64, 256, 1024, 4096, 16384] export const ch03: Chapter = { id: 'higher-order', nav: 'Two more orders, almost free', part: 'One dimension', title: 'Two more orders, almost free', blurb: 'The compact fourth-order scheme, and how to read a work-precision diagram.', text, labs: [ { id: 'orders', title: 'Second order against fourth', caption: 'Both schemes solve the same tridiagonal system; only the right-hand side differs. The second figure is the one that decides anything.', driver, script, editorOpen: true, controls: [KIND_CONTROL], defaults: { kind: 'smooth', mode: 'sweep', ns: NS, nmaxs: [16384, 16384], timed: 1 }, render: (d: SweepOut) => createElement( Fragment, null, createElement(Convergence, { key: 'c', data: d, style: { slots: ['fd2', 'fd4'], refs: [ { p: -2, label: 'slope −2' }, { p: -4, label: 'slope −4' }, ], }, }), createElement(WorkPrecision, { key: 'w', data: d, style: { slots: ['fd2', 'fd4'] } }), ), summary: (d: SweepOut) => [ { label: 'best 2nd order', value: fmtErr(Math.min(...(d.E[0].filter((v) => v != null) as number[]))) }, { label: 'best 4th order', value: fmtErr(Math.min(...(d.E[1].filter((v) => v != null) as number[]))) }, ], }, ], }